469,645 Members | 1,729 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

glob.glob unicode bug or feature

#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.
Jul 18 '05 #1
5 2144


Elbert> #Is this a bug, or a feature? I beleve it's a bug.

Dunno. Can you submit a bug report on SourceForge?

Skip

Jul 18 '05 #2
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

Jul 18 '05 #3
Peter Otten:
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 didn't work for me as os.curdir has already been added in the call
to glob1. Instead, for Python 2.3, also changing line 22 inside glob() to

return glob1(type(dirname)(os.curdir), basename)

worked.

Neil
Jul 18 '05 #4
Neil Hodgson wrote:
if not dirname:
dirname = type(dirname)(os.curdir)


This didn't work for me as os.curdir has already been added in the call
to glob1. Instead, for Python 2.3, also changing line 22 inside glob() to

return glob1(type(dirname)(os.curdir), basename)

worked.


I should have tried before posting. Now you point it out it seems I've
changed a piece of dead code. Or am I missing something ...again?

Peter

Jul 18 '05 #5
Peter Otten:
Neil Hodgson wrote:
...
return glob1(type(dirname)(os.curdir), basename)

...
I should have tried before posting. Now you point it out it seems I've
changed a piece of dead code. Or am I missing something ...again?


It took quite a few examples for me to be convinced that the code is
dead. "leve" has submitted a bug and "nnorwitz" a patch to the Python bug
tracker and it works for me:

def glob1(dirname, pattern):
if not dirname: dirname = os.curdir
+ if isinstance(pattern, unicode): dirname = unicode(dirname)

http://sourceforge.net/tracker/index...70&atid=305470

Neil

Jul 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Georgy Pruss | last post: by
4 posts views Thread by Python Dunce | last post: by
2 posts views Thread by Zain Homer | last post: by
6 posts views Thread by Hitesh | last post: by
3 posts views Thread by billiejoex | last post: by
5 posts views Thread by jo3c | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.