[Tutor] ok, I want to read a dir.
Kirk Bailey
deliberatus@my995internet.com
Wed, 26 Dec 2001 22:58:33 -0500
Say, looking this over, FILTER looks like a good candidate for this job.
files=os.listdir('./lists/') # this creates a raw dir listing
filelist=[] # create an empty list
fnmatch.filter(filelist, "*.info") # return the subset of list
which match!
this is not right, but close. What is the right way to use fnmatch and
filter?
This is the error I get:
ns# ./TLpost.py
Traceback (innermost last):
File "./TLpost.py", line 189, in ?
listname = sys.argv[1]
IndexError: list index out of range
ns#
And that puzzles hell out of me.
"Michael P. Reilly" wrote:
>
> On Wed, Dec 26, 2001 at 09:13:56PM -0500, Kirk Bailey wrote:
> > ok, it worked. Too well, it worked.
> >
> > It returned the file names, and included in the return is the path!
> >
> > Lookee:
> [lookee snipped]
>
> > See, those lines should be the bare name of the thing, a space, then the
> > firstline of the info file. Well, ir read the info file pretty slick.
> > Accessed the riretory structure just fine. Seems I want to massage the
> > elements in the list, or at least in A list, so everything but the first
> > part of the file is GONE. Strip off the path, then strip off the .info
> > part, leaving us with pure NAME. That name is the name of a list. That
> > btw is in my server now, and those are the info files for 3 lists NOW
> > working with TLpost.py NOW. snurklechortlegloat...
>
> Then you might want to look at what the glob module is doing. It uses
> os.listdir and the fnmatch module.
>
> def nopath_glob(dir, pattern):
> import os, fnmatch
>
> files = os.listdir(dir)
> results = []
> for fname in files:
> if fnmatch.fnmatch(fname, pattern):
> results.append(fname)
> return results
>
> About the only real difference is that the glob function joins the
> directory and file names together first.
>
> This is just the pedantic version.. the same thing is done with
> glob.glob1.
>
> -Arcege
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
--
Respectfully,
-Kirk D Bailey (C)2001
Addme! icq #27840081
end
Within the sweep of his sword, Each man is an Ubar.
http://www.howlermonkey.net/
http://www.sacredelectron.org/