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
4

1 回答 1

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
于 2013-07-14T07:05:47.323 回答