Python_報錯:SyntaxError: unexpected character after line continuation character
阿新 • • 發佈:2018-10-04
day ont rac exp 原因 makedirs time ror read
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