语法错误:在一种情况下行继续字符后出现意外字符,但在另一种情况下没有[关闭]

问题描述 投票:0回答:1

我在 Python 脚本中有两个几乎相同的

exec
调用。第二个结果会导致语法错误,但第一个不会。我该如何解决这个问题?

big_file = open('C:/Users\\Mark\\Documents\\Python\\Final\\ingram.txt', 'r')
small_file3 = open('C:/Users\\Mark\\Documents\\Python\\Final\\cisco.csv', 'w')
for line in big_file:
   if line[2:7] == 'CISCO':
       small_file3.write(line)
big_file.close()
small_file3.close()

exec(open("C:\\Users\\Mark\\Documents\\Python\\Final\\delete2.py").read());
exec(open("C:\\Users\\Mark\\Documents\\Python\\Final\\popcolumn1.py").read());
C:\Users\Mark>python C:\Users\Mark\Documents\Python\Final\cisco5.py
11827Traceback (most recent call last):
  File "C:\Users\Mark\Documents\Python\Final\cisco5.py", line 10, in <module>
    exec(open("C:\\Users\\Mark\\Documents\\Python\\Final\\popcolumn1.py").read());
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 19
    C:\\Users\\Mark\\Documents\\Python\\Final\
       ^
SyntaxError: unexpected character after line continuation character
python python-3.x
1个回答
-1
投票

尝试删除 ;在你的行的末尾。 python 中不需要它,它是错误告诉你的。意想不到的字符是;

© www.soinside.com 2019 - 2024. All rights reserved.