glob and curly brackets

Z

Zain Homer

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,subdir2}

.....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,subdir2}'
globlist = glob.glob(globber)

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
 
R

RunLevelZero

You just need to literlize them with a forward slash.

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

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

See if that works for you.
 
G

gry

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.
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top