Error in Windows 8 with Unicode


#1

Hi to everyone. I create a Python Script. I run it with Windows 8 an he give to me the message:

“Impossible to translate bytes [E9] at index 0 from specified code page to Unicode.”

The line of the error is:
BackGround =str(mypath+chr(92)+“backgroundimage.png”)

I think it’s the chr(92) is wrong, but i don’t know how i can fix it.

A bad solution maybe can be:
BackGround =str(mypath+"\backgroundimage.png")

Thanks.
Daniele


(Menno Deij - van Rijswijk) #2

Ok, I’m not a Python expert by a long shot, but rather than using your string concatenation, could the following maybe work

import os.path
BackGround = os.path.join(mypath, “backgroundimage.png”)

or use

BackGround = str(mypath + os.sep + “backgroundimage.png”)


#3

You should just be able to use a double backslash:

BackGround =str(mypath+"\\backgroundimage.png")

The first backslash is “escaped”…

–Mitch


(Menno Deij - van Rijswijk) #4

or use the string literal “r” notation: r"\backgroundimage.png" in a string literal you don’t have to escape any characters.

combined with the unicode “u” notation, this gets to ur"\backgroundimage.png", a Unicode string literal.


(Steve Baer) #5

I think this is the best approach since it is completely operating system agnostic.