语法错误:解析时出现意外的EOF。(使用open('myfile.txt',mode ='a')作为p:)

时间:2019-07-19 11:24:18

标签: python python-3.7

即使语法正确,我也收到“ SyntaxError:解析时出现意外的EOF”。我该如何纠正?

%%writefile mynewfile.txt
L stands for Lamborghini
M stands for Maserati
A stands for Audi
with open('myfile.txt', mode = 'r') as newfile:
     print(newfile.read())

with open('myfile.txt',mode='a') as p:
File "<ipython-input-24-c4ad87f5e304>", line 1
    with open('myfile.txt',mode='a') as p:
                                          ^
SyntaxError: unexpected EOF while parsing

1 个答案:

答案 0 :(得分:1)

尝试:

with open('myfile.txt', mode = 'r') as newfile:
     print(newfile.read())

with open('myfile.txt',mode='a') as p:
     pass

Python在while / for / if语句中不允许空块。