Syntaxerror was just reported when running the python file: ‘Unicode error)’ Unicode scape ‘codec can’t decode bytes in position 2-3: tr. in fact, the reason for this error is the escape problem.
sys.path.append('c:\Users\mshacxiang\VScode_project\web_ddt')
Cause analysis: in the windows system, the file path can be read by \, but in the Python string \, there is an escape meaning,
For example, \ t can represent tab and \ n represents line feed, so we need to take some measures to make \ not be interpreted as escape characters. There are currently 3 solutions
1. Add r before the path to keep the original value of the character.
sys.path.append(r'c:\Users\mshacxiang\VScode_project\web_ddt')
2. Replace with double backslash
sys.path.append('c:\\Users\\mshacxiang\\VScode_project\\web_ddt')
3. Replace with forward slash
sys.path.append('c:/Users/mshacxiang/VScode_project/web_ddt')
Similar Posts:
- Python:SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in pos…
- Python Open File SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in …
- How to Solve pylint error tab indent
- XML parsing & special character error
- How to Solve Python SyntaxError: EOL while scanning string literal
- Python TypeError: can only concatenate str (not “int”) to str
- Pytest executes the case.py file on the terminal error: Modulenotfounderror: no module named ‘API’
- shell :syntax error: unexpected end of file
- Python: How to Solve raise JSONDecodeError(“Expecting value”, s, err.value) from None json.decoder…
- [Solved] fsync: failed to connect to feed.openvas.org (89.146.224.58)