【问题标题】:Python simple loop EOL while scanning string literal [closed]扫描字符串文字时的Python简单循环EOL [关闭]
【发布时间】:2014-07-12 18:43:55
【问题描述】:

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

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

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

任何帮助表示赞赏

【问题讨论】:

  • print "(lines) 注意到这里有什么?

标签: python eol


【解决方案1】:

您打开双引号后忘记关闭它们,或者您可能不小心放了一个:

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()

A SyntaxError: EOL while scanning string literal 基本上意味着它正在寻找另一个引号来结束字符串,但它来到了 End Of the Line(因此 EOL),它没有找到任何东西。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-30
    • 2020-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多