Python支持中文注释

三处设置,使Python的Eclipse开发环境(使用PyDev)支持中文

-

(a)Eclipse的Window菜单Editors设置: Eclipse工具条 -> Window -> Preferences -> General -> Editors -> Text Editiors -> Spelling

image

  (b)Eclipse的Window菜单Workspace设置:     Eclipse工具条 -> Window -> Preferences -> General –> Workspace

image

 

(c)Python源代码头需要加入一个额外的编码指示说明。书《Python核心编程》第二版324页说道,只要在你的Python模块头部加入一个额外的编码指示说明就可以让导入者使用指定的编码解析你的模块。如果没有下面这行文件头部说明,在编译运行含有中文字符的Python文件时,会产生如下错误。

D:\Python27\PrivateLib>python sample.py

  File "sample.py", line 1 SyntaxError: Non-ASCII character '\xff' in file namespaces.py on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

编码指示说明:

#-*- encoding: utf-8 -*-

image

posted @ 2014-11-21 10:33  mountain_sun  阅读(3139)  评论(0编辑  收藏  举报