multiple constructor __init__

Terry Reedy tjreedy at udel.edu
Fri Feb 3 04:43:16 CET 2012


On 2/2/2012 8:09 PM, Emmanuel Mayssat wrote:
> Hello all,
>
> I would like to instantiate my class as follow
>
>
> QObject(<param1>, <parent>)
> QObject(<parent>)
>
> an example would be
> http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qmenu.html
>
> How can I do this without have to specify parent=<parent> in the second
> version
> (I always need to supply the parent parameter, but I would like to
> supply it last)

The same way range(stop) versus range(start,stop) works.
But I really recommend against that api.
It makes both doc and code messy.
You need a really good reason to not use the obvious
def __init__(self, parent, param=default):...

-- 
Terry Jan Reedy




More information about the Python-list mailing list