Cause analysis: Python \ has the meaning of escape, so the read path is wrong
import os
os.walk('C:\Users\user\Desktop\Test')
Solution:
1. Add r in front of the path to prevent character escape.
import os
os.walk(r'C:\Users\user\Desktop\Test')
2. Use a double diagonal bar to read and output a backslash
import os
os.walk(r'C:\\Users\\user\\Desktop\\Test')
Read More:
- SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 2-3: truncated \UX
- Python Error: SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 2-3:
- How to Solve Python Pandas Read or Import Files Error
- Python: How to Set Line breaks and tabs for Strings
- [Solved] SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 6-7: malformed
- [Solved] Python Pandas Read Error: OSError: initializing from file failed
- Pandas read_csv pandas.errors.ParserError: Error tokenizing data
- error: (-5:Bad argument) in function ‘seamlessClone‘ and error: (-215:Assertion failed) 0 <= roi.x && 0 [How to Solve]
- Python 3 uses the relative path import module
- [Solved] ModuleNotFoundError: No module named ‘requests‘
- Python: How to Use os.path.join()
- [Solved] SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 10-11: malformed
- pd.to_csv Error: need to escape, but no escapechar set
- [zipfile] Python packages files as zip packages & decompresses them
- [Solved] Python project runs the open() function error: FileNotFoundError: [Errno 2] No such file or directory
- [Solved] Paramiko error: AttributeError: ‘NoneType’ object has no attribute ‘time’
- [Solved] AttributeError: OperationJson instance has no attribute ‘data‘
- [Solved] C error: expected 1 fields in line 3, saw 2 processing method
- Python 3 urllib has no URLEncode attribute
- [ONNXRuntimeError] : 10 : INVALID_Graph loading model error