Reputation: 25
im using
wn.addshape(os.path.expanduser("C:\Users\Dianna Jackson\Desktop\space invaders\playerspaceinvaders.gif"))
but its not working. its saying
" File "C:\Users\Dianna Jackson\Desktop\space invaders\Space Invaders.py", line 11 wn.addshape(os.path.expanduser("C:\Users\Dianna Jackson\Desktop\space invaders\playerspaceinvaders.gif")) ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape [Finished in 0.1s with exit code 1] [shell_cmd: python -u "C:\Users\Dianna Jackson\Desktop\space invaders\Space Invaders.py"] [dir: C:\Users\Dianna Jackson\Desktop\space invaders] [path: C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Users\Dianna Jackson\AppData\Local\Smartbar\Application\;C:\Program Files (x86)\QuickTime\QTSystem;C:\Python3.8.1\Scripts;C:\sqlite3;C:\Users\Dianna Jackson\AppData\Local\Programs\Python\Python38-32\Scripts\;C:\Users\Dianna Jackson\AppData\Local\Programs\Python\Python38-32]"
i imported turtle and os please help
Upvotes: 0
Views: 111
Reputation: 70
Try saving the image file in the same folder in your computer as you are saving the code. If you are already doing this, then I'm afraid I'm not sure what's wrong.
Upvotes: 0
Reputation: 1368
The path you're providing has escape characters (\
) in it, and so it is trying to butcher your string. As you want to use your string as-is, use a raw string by prefixing it with an r
: wn.addshape(os.path.expanduser(r"C:\Users\Dianna Jackson\Desktop\space invaders\playerspaceinvaders.gif"))
Upvotes: 1