Question about glob.glob <--newbie

S

Sean Berry

r = glob.glob('/*')['/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'][]

I can do a
and that works. Why doesn't glob.glob work on /usr/websites?

What I am trying to do is write a simple script that will recursively search
for and replace key words in all files. I am doing this mainly for practice
since I already can write a shell script or use an awk/sed combo. Does
anyone have anything that does a similar task? Thanks
 
D

David M. Cooke

Sean Berry said:
['/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'][]

I can do a
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?
 
H

Heather Coppersmith

Sean Berry said:
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.

HTH,
Heather
 
D

David M. Cooke

At some point said:
Sean Berry said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,197
Messages
2,571,038
Members
47,633
Latest member
BriannaLyk

Latest Threads

Top