Newbie Using "Programming Python" 1st Ed. Question
Dennis Lee Bieber
wlfraed at ix.netcom.com
Mon Dec 16 18:51:28 EST 2002
Gerson Kurz fed this fish to the penguins on Monday 16 December 2002
09:15 am:
> b) Expand it yourself, e.g. using
>
> import os, fnmatch
>
> def expand_wildcards(pattern):
> # get name of directory without wildcards
> dirname = os.path.dirname(pattern)
>
> # get name of pattern
> pattern = os.path.basename(pattern)
>
> # list all files
> return fnmatch.filter( os.listdir(dirname), pattern )
>
Might it not be faster just to ...
import glob
filelist = glob.glob(name) #using the original poster's variable
and nest a loop:
for name in sys.argv[1:]:
for fid in glob.glob(name):
input = open(fid,'r')
...
--
> ============================================================== <
> wlfraed at ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
> wulfraed at dm.net | Bestiaria Support Staff <
> ============================================================== <
> Bestiaria Home Page: http://www.beastie.dm.net/ <
> Home Page: http://www.dm.net/~wulfraed/ <
More information about the Python-list
mailing list