即使语法正确,我也收到“ 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
答案 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
语句中不允许空块。