Class Methods with Python 2.1

F. GEIGER fgeiger at datec.at
Tue Apr 23 12:56:36 EDT 2002


"Thomas Guettler" <zopestoller at thomas-guettler.de> schrieb im Newsbeitrag
news:3CC57C5F.7040804 at thomas-guettler.de...
> Is it possible to have methods in classes
> which don't take a self argument, because
> they only change attributes common to all
> instances of a class?
>
> class car:
>      available=["porsche", "volvo", "trabbi"]
>      def __init__(self, name):
>         if name not in available:
>             raise "Name not in available cars"
>         ....
>      def add_available_car(name):
>          availalble.append(name)
>
> One solutionn is to define this method
> at module level. But that's not nice.
>
>
>
> Unfortunately I have to stick to Python2.1
>
>    thomas
>





More information about the Python-list mailing list