Question about glob.glob <--newbie

David M. Cooke cookedm+news at physics.mcmaster.ca
Tue May 4 13:34:31 EDT 2004


At some point, Heather Coppersmith <me at privacy.net> wrote:

> On Mon, 03 May 2004 23:09:27 -0400,
> cookedm+news at physics.mcmaster.ca (David M. Cooke) wrote:
>
>> At some point, "Sean Berry" <sean_berry at cox.net> wrote:
>>>>>> r = glob.glob('/*')
>>>>>> r
>>> ['/dev', '/usr', '/stand', '/etc', '/cdrom', '/proc', '/bin', '/boot',
>>> '/mnt', '/modules', '/root', '/sbin', '/tmp', '/var', '/sys', '/COPYRIGHT',
>>> '/kernel.GENERIC', '/kernel', '/compat', '/home', '/kernel.old',
>>> '/modules.old']
>>>>>> 
>>>>>> r = glob.glob('/usr/websites/*')
>>>>>> r
>>> []
>>> 
>>> I can do a
>>>>>> import os
>>>>>> dirs = os.system('ls /usr/websites')
>>> 
>>> and that works.  Why doesn't glob.glob work on /usr/websites?
>
>> Somehow, I doubt that actually works. I'll bet that dirs == 0 -- os.system
>> returns the status code of the command, not the output. You'll want
>> commands.getoutput.
>
>> What are the permissions on /usr/websites? What does 'ls -l
>> /usr/websites' and 'ls -ld /usr/websites' give?
>
> Possibly picking a nit, but is there a difference between 'ls
> /usr/websites' (without the trailing slash) and 'ls /usr/websites/'
> (with the trailing slash)?  Some OS's do strange things with some
> symbolic links and/or mount points based on the presence/absence of that
> slash.

True (linux being no exception). But then glob.glob('/usr/websites/*')
should still give the contents of whatever /usr/websites points to.

For the OP: does os.listdir('/usr/websites') work? glob.glob uses it
internally, but catches any errors it raises.

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca



More information about the Python-list mailing list