我想打印文件的行,但发生了一些语法错误。我的代码出了什么问题?
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
答案 0 :(得分: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