Skip to main content
 首页 » 编程设计

python之语法错误 : unexpected character after line continuation character in python

2025年05月04日11傻小

有人能告诉我这个程序有什么问题吗?我面对

syntaxerror unexpected character after line continuation character 

当我运行这个程序时:

f = open(D\\python\\HW\\2_1 - Copy.cp,"r");   
lines = f.readlines(); 
 
for i in lines:   
    thisline = i.split(" "); 

请您参考如下方法:

您需要引用该文件名:

f = open("D\\python\\HW\\2_1 - Copy.cp", "r") 

否则 D 之后的反斜杠被解释为换行符,并且后面应该跟一个换行符。这用于将长​​表达式扩展到多行,以提高可读性:

print "This is a long",\ 
      "line of text",\ 
      "that I'm printing." 

另外,在 Python 语句的末尾不应有分号 (;)。