Bazaar-NG traffic #2

Joel Rosdahl joel at rosdahl.net
Tue Oct 11 15:19:44 BST 2005


John A Meinel <john at arbash-meinel.com> writes:

> Magnus Therning wrote:
>
>> On Tue, Oct 11, 2005 at 08:33:17AM -0500, John A Meinel wrote:
>>
>>> Do you have any of these directories/files available? I would be
>>> curious what this returns:
>>>
>>> python -c "import os; print os.listdir(u'.')"
>>> versus
>>> python -c "import os; print os.listdir('.')"
>>>
>>> The first should try and interpret the names and return unicode,
>>> the second should just do ascii names (possibly just byte-stream
>>> names).
>>
>> Both return a list containing all the files in the current dir on
>> my Linux machine. The first one is a list of unicode strings
>> ([u'str1', u'str2']). The second is a list of regular strings
>> (['str1', 'str2']). I.e. exactly what you predicted.
>
> Naturally, I would expect that. :) What I wanted to know was what
> happens when you have non-ascii characters in that directory?
> [...]

os.listdir(u".") returns regular strings for names that can't be
decoded using the filesystem encoding.

I have made some notes about how to use Unicode in a Python-based
project of mine:

    http://kofoto.rosdahl.net/trac/wiki/UnicodeInPython

They may be useful for others too.

-- 
Regards,
Joel Rosdahl <joel at rosdahl.net>
Key BB845E97; fingerprint 9F4B D780 6EF4 5700 778D  8B22 0064 F9FF BB84 5E97




More information about the bazaar mailing list