[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] loading images with special characters on file name



Hi,

UTF-8 file paths work on Debian as well. And the unzipped file names are somewhat mangled. I suspect a Windows code page got in the way. Pygame lets SDL open files when it can. And SDL uses the standard C functions. So on Windows Pygame is at the mercy of the Visual C runtime library. But Python 3.1 uses Windows specific wide character C functions to open its files, allowing for some level of Unicode support. One can take advantage of this in Pygame by passing an open Python file to image.load rather than a file name.

As a side note, Pygame support of Unicode file names is not restricted to Python 3x. Unicode strings are accepted in Python 2.x as well.

Lenard Lindstrom

On 09/02/11 12:09 PM, Weeble wrote:
On Wed, Feb 9, 2011 at 4:49 PM, Rodolfo Neu<rneu2011@xxxxxxxxx>  wrote:
You have to create a Python module named sitecustomize.py, with the lines:
import sys
sys.setfilesystemencoding('utf-8')

Now my program is working again.
As another data-point, I tried your program and it works for me on
Ubuntu without needing a call to setfilesystemencoding. However, when
I unzipped the files in your archive they had very garbled names. I
had to manually rename them to maçã.jpeg and árvore.jpeg. I'm not sure
if that's a problem on your end or mine.

Can you open files normally in Python? E.g. does this work?:

pygame.image.load(open(filename, "rb"), filename)