Problem with os.access with unicode filenames

Walter Dörwald walter at livinglogic.de
Tue Aug 12 13:45:18 EDT 2003


TheAZN wrote:

> The os.access function gives me this error:
> 
> "UnicodeEncodeError: 'ascii' codec can't encode character '\ub4' in 
> position 31: ordinal not in range(128)"
> 
> when I use the os.access function with an Unicode string which contains a 
> character u'\u00b4'.
> 
> Oddly enough in IDLE: if I do "print u'\ub4'"  I get an error, but it 
> doesn't give me an error if I do "print u'\ub00b4'"

The message is fixed now in CVS, i.e. the UnicodeEncodeError
will now state
"UnicodeEncodeError: 'ascii' codec can't encode character u'\xb4' in
position 31: ordinal not in range(128)"

> Is there a way to get around this?  It works fine when the file name does 
> not contain that character.

This depends on your OS. posixmodule.c::posix_access() does not support
Unicode strings, but it should work if you encode the filename with your
filesystem encoding before calling os.access(). Don't know about
Windows.

Bye,
    Walter Dörwald





More information about the Python-list mailing list