2013-07-14 65 views
0

我想打印一行文件,但發生了一些語法錯誤。我的代碼有什麼問題?打印文件行時出現語法錯誤

History_Data = open("C:/lottery/Dataset/History.txt","r") 

Line = History_Data.readline() 
print Line 

History_Data.close() 

錯誤消息顯示:

PS C:\Temp> python.exe .\1.py 
    File ".\1.py", line 5 
    print Line 
      ^

SyntaxError: invalid syntax 
+1

圖片失敗。 – zhangyangyu

+1

事實上,請不要張貼文本的截圖,而是文本本身!而且,由於您似乎對Python非常新穎:請查看[PEP8](http://www.python.org/dev/peps/pep-0008/),特別是關於命名約定。 TLDR:使用'lowercase_with_underscores'作爲你的變量。 – ThiefMaster

回答

3

如果您正在使用Python 3.x中,請執行下列操作:

print(Line) 

Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32 
Type "help", "copyright", "credits" or "license" for more information. 
>>> print 1 
    File "<stdin>", line 1 
    print 1 
     ^
SyntaxError: invalid syntax 
>>> print(1) 
1 
相關問題