3rd argument to os.path.walk(): Why?

Rob Hooft rob at hooft.net
Tue Dec 12 02:17:49 EST 2000

 AM> E.g., say you want to _count_ the files:

 AM> import os

 AM> class Counter:
 AM>   def __init__(self):
 AM>     self.count = 0
 AM>   def inc(self, n=1):
 AM>     self.count += n

 AM> def count_names(count, dir, flist):
 AM>   count.inc(len(flist))

 AM> count = Counter()
 AM> os.path.walk("/", count_names, count)

 AM> print count.count,"files in all"

If you'd do this, why not make "count_names" a method of the Counter

=====   rob at hooft.net          http://www.hooft.net/people/rob/  =====
=====   R&D, Nonius BV, Delft  http://www.nonius.nl/             =====
===== PGPid 0xFA19277D ========================== Use Linux! =========

More information about the Python-list mailing list