glob and curly brackets

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Zain Homer

    glob and curly brackets

    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 in tcsh). Is there a shell standard
    for which the python glob module has been designed which
    prevents the implimentation of the {}'s?

    For example:

    I can do this from tcsh:
    ls /home/zhomer/test/{dir1*,dir2*}/{subdir1,subdir 2}

    .....and get back a result if something exists there.

    However, the python glob module doesn't recognize curly brackets.

    globber = '/home/zhomer/test/{dir1*,dir2*}/{subdir1,subdir 2}'
    globlist = glob.glob(globb er)

    doesn't work...

    I read the glob documentation and I see {} aren't included,
    but I'm thinking the curly brackets are pretty standard shell
    syntax so I'm wondering why they can't be included with
    glob?

    python glob is super useful especially since with python we don't
    have the word count limitation that some shells have when
    globbing.

    Thanks,
    -Zain


  • RunLevelZero

    #2
    Re: glob and curly brackets

    You just need to literlize them with a forward slash.

    " globber = '/home/zhomer/test/{dir1*,dir2*}/{subdir1,subdir 2}'
    globlist = glob.glob(globb er) "

    globber = '/home/zhomer/test/\{dir1*,dir2*\}/\{subdir1,subdi r2\}'
    globlist = glob.glob(globb er)

    See if that works for you.

    Comment

    • gry@ll.mit.edu

      #3
      Re: glob and curly brackets

      This would indeed be a nice feature.
      The glob module is only 75 lines of pure python. Perhaps you would
      like
      to enhance it? Take a look.

      Comment

      Working...