Hello, Python!

搞了一下午的Python,从找KNIME的SNA组件,到可视化social graph,再到iGraph和NetworkX,最后再到Python……

参考了闫小勇老师的博文和总结《从C#到Python》,百度一下到处都是,这里就不给链接了。41页,打印出来,很实用,很入门。
装了Python2.7,虽说现在Python已经有了3.x版本,但iGraph等工具包还不支持。
装了之后,又找IDE,pythonwin、PyQT配Eric4统统失败,最后锁定了PyScripter,终于跑出了第一个Hello World。
用PyScripter时,需要修改一下Python的Lib目录下的site.py,否则永远有形如“ UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-2: ordinal not in range(128)”的错误。site.py中有个函数如下:
def setencoding():
    """Set the string encoding used by the Unicode implementation.  The
    default is 'ascii', but if you're willing to experiment, you can
    change this."""
    encoding = "ascii" # Default value set by _PyUnicode_Init()
    if 0:
        # Enable to support locale aware default string encodings.
        import locale
        loc = locale.getdefaultlocale()
        if loc[1]:
            encoding = loc[1]
    if 0:
        # Enable to switch off string to Unicode coercion and implicit
        # Unicode to string conversion.
        encoding = "undefined"
    if encoding != "ascii":
        # On Non-Unicode builds this will raise an AttributeError...
        sys.setdefaultencoding(encoding) # Needs Python Unicode build !
很奇怪为什么是两个if 0,把第一个0改成1就不会有上面那个错误了。不知是不是python的bug。
发布了172 篇原创文章 · 获赞 3 · 访问量 25万+

猜你喜欢

转载自blog.csdn.net/sizheng0320/article/details/6139566