从文本文件读取输入时进行解析时,Python发生意外的EOF

时间:2018-10-06 20:24:23

标签: python parsing eof

我有以下代码,从文本文件读取数据并输出结果。一切正常,直到第20个文本文件,此后出现错误:

>>> %Run read_file_test.py
File "<unknown>", line 0

^
SyntaxError: unexpected EOF while parsing

第20个测试文件与19、18或17..1。相比没有什么不同。它恰好更长。我认为该错误发生在打印语句上。

def unitTests():
    tests=["test0.txt","test1.txt","test2.txt","test3.txt","test4.txt", "test5.txt","test6.txt","test7.txt", "test8.txt","test9.txt","test10.txt",
       "test11.txt","test12.txt","test13.txt","test14.txt","test15.txt","test16.txt","test17.txt","test18.txt","test19.txt","test20.txt"]

    for test in tests:
        with open(test) as unit:
            input = unit.read()
            data=[s.strip() for s in input.splitlines()]
            graph=[]
            for i in data:
                graph.append(ast.literal_eval(i))
            print(len(graph[1]),"\t",brute_force_vertex_cover(graph[0], graph[1], 15))#,"\t",(function(graph[0], graph[1], 15)))
     print("done")
unitTests()

感谢您的帮助。谢谢。

0 个答案:

没有答案