python improvements (Was: Re: New Language)

Moshe Zadka moshez at math.huji.ac.il
Tue May 16 00:21:18 EDT 2000


On 16 May 2000, Bernhard Herzog wrote:

> In that situation, real class methods would have been useful and cleaner
> than any other solution. In the end, I fell back to normal class
> attributes that are computed at class definition time because it works
> well enough for the time being.


Let me reiterate the way to get class methods:

class Function:

	def __init__(self, func):
		self.func = func

	def __call__(self, *args, **kw):
		return apply(self.func, args, kw)

class SomeClass:

	def class_method(a, b, c):
		return a+b+c
	class_method = Function(class_method)

At the addition of a constant overhead (the "Function" definition), and
one-line per class method (which you'd need anyway, to signal it is a
class method), you get a no-brainer solution.

try-meta-classes-for-more-fun-ly y'rs, Z.
--
Moshe Zadka <moshez at math.huji.ac.il>
http://www.oreilly.com/news/prescod_0300.html
http://www.linux.org.il -- we put the penguin in .com





More information about the Python-list mailing list