Python syntaxerror: (unicode error) 'Unicodeescape' codec can't Decode Bytes in position 2-3: TR

created at 06-26-2021 views: 12

Hello ~ Happy New Year, I haven't updated for a long time, I just got the error SyntaxError: (Unicode Error) 'Unicodeescape' codec can't Decode, which is acts, in position 2-3: Tr . The reason for the mistake is the problem of escape.

For example, the file path I passed in the file is like this.


Cause Analysis: Read the file path in the Windows system to use \, but in the python string, there is a synonymous meaning, such as \ t can represent Tab, \ n represents the wrap, so we need to take some way to make \ not Interpretation is essential characters. There are currently three solutions

1  plus R in front of the path, that is, keep the character's original value.


2 replace the double reverse slope


3  replace it as a forward slash

created at:06-26-2021
edited at: 06-26-2021: