Question about glob.glob <--newbie

Discussion in 'Python' started by Sean Berry, May 4, 2004.

  1. Sean Berry

    Sean Berry Guest

    >>> 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?

    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
    Sean Berry, May 4, 2004
    #1
    1. Advertising

  2. At some point, "Sean Berry" <> 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?

    --
    |>|\/|<
    /--------------------------------------------------------------------------\
    |David M. Cooke
    |cookedm(at)physics(dot)mcmaster(dot)ca
    David M. Cooke, May 4, 2004
    #2
    1. Advertising

  3. On Mon, 03 May 2004 23:09:27 -0400,
    (David M. Cooke) wrote:

    > At some point, "Sean Berry" <> 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.

    HTH,
    Heather

    --
    Heather Coppersmith
    That's not right; that's not even wrong. -- Wolfgang Pauli
    Heather Coppersmith, May 4, 2004
    #3
  4. At some point, Heather Coppersmith <> wrote:

    > On Mon, 03 May 2004 23:09:27 -0400,
    > (David M. Cooke) wrote:
    >
    >> At some point, "Sean Berry" <> 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
    David M. Cooke, May 4, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Georgy Pruss
    Replies:
    15
    Views:
    714
    Tim Roberts
    Dec 1, 2003
  2. Tim Peters
    Replies:
    1
    Views:
    349
    Duncan Booth
    Dec 1, 2003
  3. Elbert Lev

    glob.glob unicode bug or feature

    Elbert Lev, Jul 31, 2004, in forum: Python
    Replies:
    5
    Views:
    382
    Neil Hodgson
    Aug 2, 2004
  4. Hitesh

    glob.glob output

    Hitesh, Mar 12, 2007, in forum: Python
    Replies:
    6
    Views:
    385
    Hitesh
    Mar 13, 2007
  5. billiejoex

    glob.glob standardization

    billiejoex, Jun 27, 2007, in forum: Python
    Replies:
    3
    Views:
    261
    Tim Roberts
    Jun 29, 2007
Loading...

Share This Page