Python glob and raw string

Chris Angelico rosuav at gmail.com
Thu Jan 16 13:19:47 EST 2014


On Fri, Jan 17, 2014 at 5:14 AM, Neil Cerutti <neilc at norwich.edu> wrote:
> class Miner:
>     def __init__(self, archive):
>         # setup goes here; prepare to acquire the data
>         self.descend(os.path.join(archive, '*'))
>
>     def descend(self, path):
>         for fname in glob.glob(os.path.join(path, '*')):
>             if os.path.isdir(fname):
>                 self.descend(fname)
>             else:
>                 self.process(fname)
>
>     def process(self, path):
>         # Do what I want done with an actual file path.
>         # This is where I add to the data.
>
> In your case you might not want to process unless the path also
> looks like an xml file.
>
> mine = Miner('myxmldir')
>
> Hmmm... I might be doing too much in __init__. ;)

Hmm, why is it even a class? :) I guess you elided all the stuff that
makes it impractical to just use a non-class function.

ChrisA



More information about the Python-list mailing list