[BUG] Unicode string must be always used with encodings

Robey Pointer robey at lag.net
Tue Sep 27 02:51:22 BST 2005

On 26 Sep 2005, at 13:00, Alexander Belchenko wrote:

> John A Meinel пишет:
>>> * for decode filenames to unicode strings it must be used  
>>> user_encoding
>> I'm not sure about this last one. For instance, most Linux systems  
>> use utf-8 as the encoding. And Windows uses UTF-16 (of which  
>> python doesn't seem able to read).
> When I print out os.listdir() list of one of my directory with  
> files that have russian filenames, I see that all filenames is flat  
> string, not unicode string. Based on this behaviour of my Python  
> 2.4.0 I make last assumption. May be I am wrong, but now on my  
> system bzr is fails every time when I simply try to list with bzr  
> those directories.

The trick is to use a unicode string for os.listdir:

 >>> os.listdir('/Users/robey/crap')
['rand\xc3\xb8m stuff']
 >>> os.listdir(u'/Users/robey/crap')
[u'rand\xf8m stuff']


More information about the bazaar mailing list