os.path.exists and unicode filenames

Peter Bienstman Peter.Bienstman at ugent.be
Tue Nov 7 14:13:25 EST 2006


Hi,

I'm trying to add support for unicode file names to my application.

I'm running into problems with e.g. the os.path.exists routine, which 
complains if it gets passed a unicode string:

Traceback (most recent call last):
  File "/usr/lib/python2.4/site-packages/mnemosyne/pyqt_ui/main_dlg.py", line 
149, in fileNew
    if os.path.exists(out):
  File "/usr/lib/python2.4/posixpath.py", line 171, in exists
    st = os.stat(path)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 24-29: 
ordinal not in range(128)

I could try encoding the string in utg-8, but then it wouldn't work under 
Windows.

Is there an elegant cross-platform solution for this?

Thanks!

Peter



More information about the Python-list mailing list