Python_ Syntax error: unexpected character after line continuation character
Reason: the content of the written file is incorrect and should be processed as a string
>>> import os >>> os.makedirs(time_year+"\\"+time_month+"\\"+time_day)#where time_year, time_month, time_day are all variables with assigned values >>> os.chdir(time_year\time_month\time_day)# The problem is here, it's not written correctly File "<stdin>", line 1 os.chdir(time_year\time_month\time_day) ^ SyntaxError: unexpected character after line continuation character
This is OK: os.chdir (time_ year+”\\”+time_ month+”\\”+time_ day)
Refer to the writing method of creating directory in the first line
>>> os.chdir(time_year+"\\"+time_month+"\\"+time_day)#Correct >>> with open(time_hours+".txt", "w+") as fp:#This method will go to the next step normally ... fp.read() ...
Read More:
- Python Error: bash syntax error near unexpected token `newline’
- SyntaxError: Non-ASCII character ‘\xe5‘ in file [How to Solve]
- Python syntax error except exception, e: ^ syntax error: invalid syntax
- Python: How to Set Line breaks and tabs for Strings
- Pychar can’t connect to Python console, but it can run. Py file, and Anaconda’s command line can run Python command
- [Solved] Python operate Kafka error: SyntaxError: invalid syntax
- How to Fix Errors encountered in executing Python scripts with command line parameters
- [Solved] Python sqlite3.OperationalError: near “?“: syntax error
- Chromdriver Install error: File “C:\python37\lib\site-packages\selenium\webdriver\common\service.py”, line 76, in start stdin=PIPE) File…
- How does Python output colored fonts in the CMD command line window
- Python Run Error: TypeError: hog() got an unexpected keyword argument ‘visualise‘”
- Python Use sqlalchemy Error: pymssql.ProgrammingError: (102, b“Incorrect syntax near ‘(‘.DB-Lib error
- [Solved] Failed to install PIP for MacOS, prompt: syntax error: invalid syntax
- Python installs virtualenv through PIP and always reports an error: response.py“, line 438, in _error_catcher yield
- [Solved] PIP Install tensorflow error: syntax error: invalid syntax
- [Solved] NPM install Error: check python checking for Python executable python2 in the PATH
- Invalid python sd, Fatal Python error: init_fs_encoding: failed to get the Python cod [How to Solve]
- How to Solve Python WARNING: Ignoring invalid distribution -ip (e:\python\python_dowmload\lib\site-packages)
- Syntaxerror: unexpected EOF while parsing solution and ideas
- [Solved] opencv-python: recipe for target ‘modules/python3/CMakeFiles/opencv_python3.dir/all‘ failed