SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
I wrote this code :
from playsound import playsound
playsound('C:\Users\City Computer\Music\New folder\\play.mp3')
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
I wrote this code :
from playsound import playsound
playsound('C:\Users\City Computer\Music\New folder\\play.mp3')
Here, \U
in the path 'C:\Users...
starts an eight-character Unicode escape, such as \U00014321.
In your code, the escape is followed by the character 's', which is invalid. (As explained here)
There are three ways to solve this issue
1. Duplicate all backslashes (basically escape the escape character)
'C:\\Users\\City Computer\\Music\\New folder\\play.mp3'
2. Prefix the string with r (to produce a raw string)
r'C:\Users\City Computer\Music\New folder\play.mp3'
3. Use forward slashes(/) to avoid confusion
'C:/Users/City Computer/Music/New folder/play.mp3'