\b iis a no no on windows

Hey everyone. Today I was moving things around into different files/folders and updated their file path links. When I started my game to make sure I had everything mark right, I notice a error kept poping up saying Imagear.png didn’t load up. I have no Imagear.png, but I did have a Image\bar.png. As I dove in to look at the error it said Image\x08ar.png was unable to load up… for some reason \b is returning a hex value… Anyone else get this error?

In Python (as in several other languages), the backslash character is a special escape character that means the next character or characters are to have special meaning. In particular, ‘\b’ is the special ASCII 8 character.

If you really want to write a backslash in Python, you have to use a double backslash, e.g. ‘Image\bar.png’. But note that Panda’s convention is to use forward slashes, not backslashes: ‘Image/bar.png’, so if you’re using any Panda call like loadModel() or loadTexture() or whatever, you should always use forward slashes. If you’re using a standard Python call like open() or something, this doesn’t apply; but you’ll find that forward slashes generally work anyway, and so it’s not a bad habit to get into.

David

Would it not just be wise to do it the other way? I mean… windows it self shows \ for its path ways… so / should be the special meaning you would think. Anyways…

Thanks… I thought that was the problem, but wasn’t sure. So far it’s just been with \b so it was a little werid to see that error out of no where.

I agree that it’s silly to use the same character as a path delimiter and as an escape character, but Microsoft didn’t ask for my advice when they decided to use the backslash as a path delimiter.

David

MS is sorta slow sometimes… lol

I see why I just now had that error… I guess I always used / instead of the \ key XD I just had forgoten about it till now.

i might want to add that it’s microsoft who decided to to it “wrong” everyone else used / but since M$ loves to break compatibility with other products they usualy do things just different enough to break it for everyone else.

You can also use raw strings if you don’t want to use escapes:

filename = r"Image\bar.png"

But yeah, using a forward slash is probably better anyways.