【问题标题】:For loop: Syntax Error: mismatched input '' expecting EOFFor循环:语法错误:不匹配的输入''需要EOF
【发布时间】:2013-05-15 19:49:02
【问题描述】:

我正在使用 jython 2.5.1 和 netbeans,

我有以下代码:

import csv
import pprint
import os

column=[]
mycsv = csv.reader(open('F:\lia1.csv'))
for row in mycsv:
    text = row[0].strip()

if text.isdigit():
    column.append(text[-4:])


out=' '.join(column)

f2=open('F:\somefile.txt','w')
f1=open("F:\xml1.txt","r") 

for item in out:
    try:
        text = f1.readline()
        text = text.replace("Keys1028","Keys"+str(item))
        f2.write(text)

我有以下错误:

 for item in out:
    ^
SyntaxError: mismatched input '' expecting EOF

如果我注释掉尝试:我得到:

  for item in out:
    ^
SyntaxError: mismatched input '' expecting EOF

我该如何解决这个问题?

【问题讨论】:

  • 您的意思是添加except: 语句吗?
  • 您需要向我们展示更多您的代码,因为我们的out 定义不完整也不
  • 还要注意"F:\xml1.txt"中的\x会进行无效转义,请改用r"F:\xml1.txt"
  • Martin,'out' 列表由数百个 4 位字符串组成。我正在使用 try 因为从我读到的内容中,将它与流一起使用是一种很好的做法。这有帮助吗?
  • 您是从文本编辑器中完全复制的吗?看起来您以 ' 开始一个字符串,但在循环之前的最后一个 open 中以 " 结束,可能是 'r"

标签: python jython


【解决方案1】:

我认为这与语句的嵌套有关。

错误由以下人员修复:

with open("c:/whatever") as one_file:
    with open("c:/otherlocation") as other_file:
        pass  #  or do things

请看with keyword and jython 2.5.1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-01
    相关资源
    最近更新 更多