glob.glob unicode bug or feature
Peter Otten
__peter__ at web.de
Sat Jul 31 16:16:31 EDT 2004
Elbert Lev wrote:
> #Here is the script
> #Python 2.3 on W2K
>
> import glob
>
> name = glob.glob(u"./*.mp3")[0]
> print type(name)
> name = glob.glob(u"*.mp3")[0]
> print type(name)
>
> ##OUTPUT##
> #<type 'unicode'>
> #<type 'str'>
>
> #Is this a bug, or a feature? I beleve it's a bug.
The information whether glob() was passed a unicode or str is lost in the
following line in glob.glob1():
if not dirname: dirname = os.curdir
A quick fix would be
if not dirname:
dirname = type(dirname)(os.curdir)
This will work if os.curdir consists entirely of characters in the ASCII
range, which I believe to be the case for all available platforms. Is there
a portable way to convert a str filename to unicode or should the os module
grow a unicode curdiru (uuugly name, but there already is os.getcwdu())?
Peter
More information about the Python-list
mailing list