Grechka00
Grechka00

Reputation: 1

FileNotFoundError: [Errno 2] No such file or directory [Python]

[enter image description here] (https://i.sstatic.net/JVxe2.png) I'm writing a discord bot and I got an error FileNotFoundError: [Errno 2] No such file or directory The full path to the file is already specified, but the error still occurs.

I already specified the full path, but I got an error Error "(unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape. I assigned r but this error occurred.

Upvotes: 0

Views: 1036

Answers (1)

The Myth
The Myth

Reputation: 1218

The problem is raw strings don't escape single \ since the program thinks you want to escape the next character. For example, \' escapes the ' string. Therefore, to make your code function simply replace single \ with double \\ and you can remove the raw string. Example:

location = r'C:\Users\ABC' # is invalid
location = 'C:\\Users\\ABC' # is valid

Recommendation: Please don't add image links next time, and provide code as snippets rather than a hyperlink.

Upvotes: 2

Related Questions