[Python-Dev] Object customization

Moshe Zadka Moshe Zadka <mzadka@geocities.com>
Sat, 15 Apr 2000 19:44:25 +0200 (IST)


On Sat, 15 Apr 2000, Tim Peters wrote:

[Barry]
> Works for me!  I think function attrs would be a lousy place to put
> statics anyway.

[Tim Peters]
> Yes, but the alternatives are also lousy:  a global, or abusing default
> args.
<snipped examples>

Personally I kind of like the alternative of a class:

class _Foo:
	def __init__(self):
		self.n = 0

	def f(self):
		self.n = self.n+1
		return 42

f = _Foo().f

getting-n-out-of-f-is-left-as-an-exercise-ly y'rs, Z.
--
Moshe Zadka <mzadka@geocities.com>. 
http://www.oreilly.com/news/prescod_0300.html
http://www.linux.org.il -- we put the penguin in .com