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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM