473,480 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

glob.glob standardization

os.listdir(path) return a list of file names independently if the path-
argument used is absolute or relative:
>>os.getcwd()
'/home/user'
>>os.listdir('Desktop')
['file.py']
>>os.listdir('/home/user/Desktop')
['file.py']

glob.glob, instead, return file names only if given path is relative:
>>os.chdir('Desktop')
os.getcwd()
'/home/user/Desktop
>>glob.glob("*")
['file.py']

....and absolute file names if given path is absolute:
>>glob.glob('/home/user/Desktop/*')
['/home/user/Desktop/file.py']

Don't you think it would be more convenient for glob.glob to return
file names only in any case, like os.listdir do?

Jun 27 '07 #1
3 1895
billiejoex <gn****@gmail.comwrote:
Don't you think it would be more convenient for glob.glob to return
file names only in any case, like os.listdir do?
AFAIK it's a wanted behavior. The doc says:

"""
Notice how any leading components of the path are preserved.
"""
--
Lawrence, oluyede.org - neropercaso.it
"It is difficult to get a man to understand
something when his salary depends on not
understanding it" - Upton Sinclair
Jun 27 '07 #2
Don't you think it would be more convenient for glob.glob to return
file names only in any case, like os.listdir do?
No. Use glob.glob1 if you want a list of files.

Regards,
Martin
Jun 28 '07 #3
billiejoex <gn****@gmail.comwrote:
>...
glob.glob, instead, return file names only if given path is relative:
>>>os.chdir('Desktop')
os.getcwd()
'/home/user/Desktop
>>>glob.glob("*")
['file.py']

...and absolute file names if given path is absolute:
>>>glob.glob('/home/user/Desktop/*')
['/home/user/Desktop/file.py']

Don't you think it would be more convenient for glob.glob to return
file names only in any case, like os.listdir do?
Martin gave you the real answer, but you should realize that your analysis
of the behavior is faulty. In EACH case, glob.glob has returned all of the
names that exactly match your pattern. It's not about absolute or
relative. For example, if you do
glob.glob( '..' )
which is a relative path, then the names you get back will be
['../xxx','../xxy','../xxz']. They're not file names only.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jun 29 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
3053
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 ...
5
2317
by: Elbert Lev | last post by:
#Here is the script #Python 2.3 on W2K import glob name = glob.glob(u"./*.mp3") print type(name) name = glob.glob(u"*.mp3") print type(name)
4
3418
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...
2
5002
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
3278
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
2353
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 =...
1
1823
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...
0
1129
by: p.lavarre | last post by:
http://wiki.python.org/moin/glob now mentions: The glob module lists names in folders that match Unix shell patterns. If the elemental function emulating Unix bash `echo *` really is missing...
5
2389
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...
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7043
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
6921
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5336
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4776
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.