defining a method inside of another method

Felix Thibault felixt at dicksonstreet.com
Wed Dec 15 03:08:46 EST 1999


This is probably a trivial question, but it's driving me crazy:

I have a class that has methods that look like this:

class Eggs:
	def keep(self, inlist):
		keepers = filter(self.choose, inlist)
		mn = {}
		for name, stuff, idont, careabout in keepers:
			mn[name] = ()
		def mystacks(dict = mn):
			return dict.copy()
		self.stacker = mystacks
		return keepers

Both keep and stacker get called as self.keep(inlist) and self.stacker() in
other methods, and they both work like they're supposed to. In keep, I have
2 names in the header, and self gets passed in as the first argument- but
if self were being passed in as the first argument  to stacker wouldn't it
overwrite dict and mess up mystacks ??? Where does it go? What am I missing?
 
Thanks!

Felix





More information about the Python-list mailing list