__init__ like in java

Aahz Maruch aahz at panix.com
Fri Dec 22 10:22:12 EST 2000


In article <91vosi$19h$1 at reader1.imaginet.fr>,
Gilles Lenfant <glenfant at equod.com.nospam> wrote:
>
>Is there an *elegant pythonic*  way to have several constructors for one
>class ?

What do you mean?  The standard way of handling this in Python is to use
default arguments:

class foo:
    __init__(self, bar=None, baz=None):
        if bar:
            ...
        if baz:
            ...
        ...

Now you can create an instance of foo() using zero, one, or two
arguments.
-- 
                      --- Aahz (Copyright 2000 by aahz at pobox.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

I don't really mind a person having the last whine, but I do mind
someone else having the last self-righteous whine.  --Aahz



More information about the Python-list mailing list