码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2018-10-04 18:58:27      阅读:427      评论:0      收藏:0      [点我收藏+]

标签:操作   原因   变量   error:   pen   写法   ted   ati   expec   

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\time_month\time_day)#问题出在这里,写法不对
  File "<stdin>", line 1
    os.chdir(time_year\time_month\time_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

标签:操作   原因   变量   error:   pen   写法   ted   ati   expec   

原文地址:https://www.cnblogs.com/rychh/p/9742769.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!