[Pythonmac-SIG] How do you use macfs.FInfo?

Jack Jansen jack@oratrix.nl
Mon, 11 Oct 1999 16:46:48 +0200


That's fairly easy to fix: move the initialization of lcounter to outside the 
function and move your global statement to the top of the function (I'm not 
sure whether the latter is really needed, but everyone puts global statements 
at the top of their functions).

And, while you're at it, in your first print statement replace "runtime" by 
"lcounter".

In general, by the way, once you need global variables you're on the road to 
making your program more complex and it's better to use objects and classes. 
This program would become something like:

class Walker:
	def __init__(self):
		self.lcounter = 0

	def run(self, change):
		self.change = change
		....

		self.walktree(fss.as_pathname)
		....

	def walktree(self, name):
		... # Replace change with self.change, walktree with
		    # self.walktree, lcounter with self.lcounter

if __name__ == '__main__':
	Walker().run(1)
--
Jack Jansen             | ++++ stop the execution of Mumia Abu-Jamal ++++
Jack.Jansen@oratrix.com | ++++ if you agree copy these lines to your sig ++++
www.oratrix.nl/~jack    | see http://www.xs4all.nl/~tank/spg-l/sigaction.htm