我想我遇到了編碼問題。當我更改爲utf-16時,錯誤更改爲第一行「導入溫度」簡單整數賦值語法錯誤無效
我安裝了Python 3.x,認爲它可能是版本問題,但是症狀相同。
我一直在運行的其他練習腳本工作正常。有任何想法嗎?
的Python表示在 「溫度= 0」
發生語法錯誤##### modules.py文件def ftoc(temp):
return (5.0/9.0) * (temp - 32.0)
def ctof(temp):
return (9.0/5.0) * temp + 32.0
結果校正後
import temperature
temp = 212
convTemp = temperature.ftoc(temp)
print("The converted temp is " + str(convTemp))
temp = 0
convTemp = temperature.ctof(temp)
print("The converted temp is " + str(convTemp))
#### temperature.py文件內容 來自原始帖子的代碼。
hostname$ python modules.py
Traceback (most recent call last):
File "modules.py", line 1, in <module>
import temperature
File "/Users/[myusername]/Dropbox/python/temperature.py", line 1
SyntaxError: Non-ASCII character '\xfe' in file /Users/[myusername]/Dropbox/python/temperature.py on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
hostname$
你錯過了上一行一個右括號。 – roippi