请问这个代码错在哪里
>>>str = r'C:\Program Files\Go Man\'SyntaxError: EOL while scanning string literal
而
>>>str = r'C:\Program Files\Go Man\\'
就没问题,
print(str)之后可以输出
C:\Program Files\Go Man\\ ,最后双反斜杠 本帖最后由 sunrise085 于 2020-4-27 08:35 编辑
字符串不能以反斜杠'\'结尾。
若真的需要的话,有两种方式
str = r'C:\Program Files\Go Man\\'[:-1]
str = r'C:\Program Files\Go Man'+"\\" 建议:
str ='C:/Program Files/Go Man/' SyntaxError- EOL while scanning string literal
An EOL ( End of Line ) error indicates that the Python interpreter expected a particular character or set of characters to have occurred in a specific line of code, but that those characters were not found before the end of the line . This results in Python stopping the program execution and throwing a syntax error .
建议用\str =r'C:/Program Files/Go Man/' 建议直接input,复制结果 sunrise085 发表于 2020-4-27 00:47
字符串不能以反斜杠'\'结尾。
若真的需要的话,有两种方式
str = r'C:\Program Files\Go Man'+"\\"
会报错 zltzlt 发表于 2020-4-27 08:06
会报错
是不是论坛又把反斜杠吞掉了{:10_327:} 原始字符串不能以反斜杠结尾,如果需要可以这样灵活处理:
>>> str = r'C:\Program Files\Go Man''\\' # 相当于 r'C:\Program Files\Go Man' + '\\'
>>> print(str)
C:\Program Files\Go Man\ liuzhengyuan 发表于 2020-4-27 08:11
是不是论坛又把反斜杠吞掉了
是的 或者:
str ='C:\\Program Files\\Go Man\\' zltzlt 发表于 2020-4-27 08:06
会报错
呃,是编辑问题,本来是俩反斜杠的。放到代码中,就变成一个了。修改了
页:
[1]