473,378 Members | 1,321 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 2314


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Georgy Pruss | last post by:
On Windows XP glob.glob doesn't work properly for files without extensions. E.g. C:\Temp contains 4 files: 2 with extensions, 2 without. C:\Temp>dir /b * aaaaa.aaa bbbbb.bbb ccccc ddddd ...
4
by: Python Dunce | last post by:
I've run into an issue with glob and matching filenames with brackets '' in them. The problem comes when I'm using part of such a filename as the path I'm passing to glob. Here's a trimmed down...
10
by: Larry Hastings | last post by:
I'm an indie shareware Windows game developer. In indie shareware game development, download size is terribly important; conventional wisdom holds that--even today--your download should be 5MB or...
2
by: Zain Homer | last post by:
Someone please let me know if I'm sending this to the wrong email alias... I'm wondering why we can't use the glob module to glob with curly brackets like we can from the command line (at least...
6
by: Hitesh | last post by:
import string import os f = open ("c:\\servername.txt", 'r') linelist = f.read() lineLog = string.split(linelist, '\n') lineLog = lineLog #print lineLog for l in lineLog:
8
by: mark.bergman | last post by:
I am porting from Digital Unix to Linux (RHEL 4), and am seeing a difference in the return value of glob(). Given a non-existant directory "/tmp/a", and the following line of code: result =...
3
by: billiejoex | last post by:
os.listdir(path) return a list of file names independently if the path- argument used is absolute or relative: '/home/user' glob.glob, instead, return file names only if given path is...
1
by: crybaby | last post by:
when I do this in my python code and run it in windows xp, it creates ctemp/..../.../.../../ so on and creates file t. Not file starting with the name complist and ending with .txt...
5
by: jo3c | last post by:
hi everyone happy new year! im a newbie to python i have a question by using linecache and glob how do i read a specific line from a file in a batch and then insert it into database? because...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.