标签:
编码格式的问题,提示页面给出了解决办法:
Defining Python Source Code Encodings To define a source code encoding, a magic comment must be placed into the source files either as first or second line in the file, such as: # coding=<encoding name> or (using formats recognized by popular editors) #!/usr/bin/python # -*- coding: <encoding name> -*- or #!/usr/bin/python # vim: set fileencoding=<encoding name> :
在代码顶部加入编码格式声明即可,我的代码文件在notepad下打开提示是gb2312格式,加入如下声明运行成功:
#!/usr/bin/python # -*- coding: GBK -*-
语法错误。很多情况是因为python2.x和python3.x语法不同引起的。比如:
python2.x,print是一个表达式,要写 print i python3.x,print是一个函数,所以要写 print(i)
标签:
原文地址:http://www.cnblogs.com/binyue/p/4745424.html