Python is wierd!

Christian Tanzer tanzer at swing.co.at
Wed Jul 26 01:18:45 EDT 2000


"Rainer Deyke" <root at rainerdeyke.com> wrote:

> Static variables and methods are a mess anyway. In Python, there is no
> need for them - just place the variables and functions outside the
> class.

That's a strong statement. But it is not true.

If you write code using classes as first-class objects, class
variables and methods can be very useful.

As Moshe Zadka recently demonstrated, there even is a way to get class
methods in Python:

> 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)

Of course, you can go out of your way and go from class to module to
module variable/function, but then that really is a mess.

-- 
Christian Tanzer                                         tanzer at swing.co.at
Glasauergasse 32                                       Tel: +43 1 876 62 36
A-1130 Vienna, Austria                                 Fax: +43 1 877 66 92





More information about the Python-list mailing list