Python简单循环EOL,同时扫描字符串文字

时间:2014-07-12 18:43:56

标签: python eol

我正在尝试逐行写出文本文件但是我一直收到以下错误:

文件“E:\ Print \ test.py”,第8行 打印“(行)
语法错误:扫描字符串文字时的EOL

myfile = open('log.txt', 'r')
count =  0
while 1:
    lines = myfile.readline()
    if not(lines):
        break
    count = count + 1
    print "(lines)
myfile.close()

任何帮助表示赞赏

1 个答案:

答案 0 :(得分:0)

打开它们后忘了关闭双引号,或者偶然放一个双引号:

print "(lines)

以下是您编辑的代码:

myfile = open('log.txt', 'r')
count =  0
while 1:
    lines = myfile.readline()
    if not(lines):
        break
    count = count + 1
    print(lines)
myfile.close()

SyntaxError: EOL while scanning string literal基本上意味着它正在寻找另一个引用来结束字符串,但它来到 E nd O f L ine (因此 EOL ),它没有找到任何东西。