Python_报错:SyntaxError: unexpected character after line continuation character

Posted 翻滚的小强

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python_报错:SyntaxError: unexpected character after line continuation character相关的知识,希望对你有一定的参考价值。

Python_报错:SyntaxError: unexpected character after line continuation character

原因:写入的文件内容不正确,应处理为字符串

>>> import os
>>> os.makedirs(time_year+"\"+time_month+"\"+time_day)#其中的time_year、time_month、time_day都是有赋值的变量
>>> os.chdir(time_year	ime_month	ime_day)#问题出在这里,写法不对
  File "<stdin>", line 1
    os.chdir(time_year	ime_month	ime_day)
                                          ^
SyntaxError: unexpected character after line continuation character

写成这样就ok了:os.chdir(time_year+"\"+time_month+"\"+time_day)

参照第一行的创建目录的写法

>>> os.chdir(time_year+"\"+time_month+"\"+time_day)#正确的
>>> with open(time_hours+".txt","w+") as fp:#此种方法能正常进入下一步操作
...     fp.read()
...

 

以上是关于Python_报错:SyntaxError: unexpected character after line continuation character的主要内容,如果未能解决你的问题,请参考以下文章