Interpreting non-ascii characters.

Omari Norman omari at smileystation.com
Tue Jul 17 18:54:55 EDT 2007


> I want to create a script which reads files in a
> current directory and renames them according to some
> scheme. The file names are in Russian - sometimes 
> the names encoded as win-1251, sometimes as koi8-r etc. 
> I want to read in file name and convert it to list for 
> further processing. The problem is that Python treats 

Apparently os.listdir returns a list of Unicode objects if the pathname
you give it is a Unicode object. So, Python should then convert the
Russian filenames to Unicode, using whatever encoding necessary. (I
don't know, however, how Python would know what to do if the filenames
are in a bunch of different encodings, as you say.)

If you can get the filenames into Unicode, then you can manipulate them
however you like.


-- 
For help at any time, press *H.



More information about the Python-list mailing list