How do I import everything in a subdir?

Cyril BAZIN cyril.bazin at gmail.com
Mon Mar 7 04:24:50 EST 2005


Hello,

If you want to look for the files "*.py" in a directory, don't use
shell command!!!
You have many ways to access the content of a directory in Python.

For exemple, you can use the glob module:

>>> import glob
>>> glob.glob('./[0-9].*')
['./1.gif', './2.txt']
>>> glob.glob('*.gif')
['1.gif', 'card.gif']
>>> glob.glob('?.gif')
['1.gif']

You might look at this page "http://docs.python.org/lib/module-glob.html". 

Cyril



More information about the Python-list mailing list