Hi,

I'm using the os.walk function for parsing files from an external mass-storage 
such as usbkey.

When i try the following code, i have an error:

from __future__ import unicode_literals

import sys
reload(sys)
sys.setdefaultencoding('utf_8')

for dirname, dirnames, filenames in os.walk(os.path.join(massStorage, path)):
or
for dirname, dirnames, filenames in os.walk(unicode(path, 'utf-8')

And my error is:
'ascii' codec can't encode character u'\xe9' in position 58: ordinal not in 
range(128)

The wrong character is an accent (french one).

It doesn't work when i start it but after a reboot i need to restart the code 
to make it work properly without any error.

Any idea about the first fact related to the usf-8 support with external files 
that can be encoded with any charset (latin-1, utf-8, ... )

Secondly, why it can works after a restart of the python script ?

BR

Thierry GAYET



-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to