Python is wierd!

Christian Tanzer tanzer at swing.co.at
Thu Jul 27 01:47:07 EDT 2000


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

> "Christian Tanzer" <tanzer at swing.co.at> wrote in message
> news:m13HJaf-000wcDC at swing.co.at...
> >"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.
> 
> If you need an object that acts like a class with added features, you can
> write a wrapper around the class.
> 
> class class_with_extra:
>   def __init__(self, it, **extras):
>     self.__dict__.update(extras)
>     self.it = it
>   def __getattr__(self, name):
>     return getattr(self.it, name)

Sure you can. But it will make your design messier than by using class
variables and methods -- you'll end up with twice as many classes and
a can of worms wo worry about (<hint> how many wrappers can a single
class have?). 

In Python, a class is an object to which attributes can be attached.
There is no need for a wrapper.

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