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
- [Solved] SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 6-7: malformed
- [Solved] SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 10-11: malformed
- Python Error: SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 2-3:
- [Solved] SyntaxError: (unicode error) ‘utf-8’ codec can’t decode byte 0xbe in position 0
- [Solved] UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xbf in position 7: invalid start byte
- How to Solve Pytorch DataLoader Loading Error: UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xe5 in position 1023
- [Solved] Grid Search Error (GridSearchCV): ‘ascii‘ codec can‘t encode characters in position 18-20: ordinal not in r
- [Solved] git review Error: UnicodeDecodeError: ‘gbk‘ codec can‘t decode
- [Exception]’ascii’ codec can’t decode byte 0xe8 in position 2: ordinal not in range(128)
- Django CSV file Error: UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xb5 in position 0: invalid start
- [Solved] RuntimeError: function ALSQPlusBackward returned a gradient different than None at position 3, but t
- [Solved] Can‘t pickle local object ‘_createenviron.<locals>.encodekey‘
- AttributeError: can‘t set attribute [How to Solve]
- can‘t multiply sequence by non-int of type ‘numpy.float64‘
- [Solved] YOLO v5 Error: AttributeError: Can‘t get attribute SPPF on module models
- Flask Database Migration Error: ERROR [flask_migrate] Error: Can‘t locate revision identified by ‘a1c25fe0fc0e‘
- [Solved] transformers Install Error: error can‘t find rust compiler
- Typeerror in Python regular expression: expected string or bytes like object
- [Solved] Pytorch Tensor to numpy error: RuntimeError: Can‘t call numpy() on Tensor that requires grad.报错