Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
multiple constructor __init__
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Chris Rebert  
View profile  
 More options Feb 2, 8:24 pm
Newsgroups: comp.lang.python
From: Chris Rebert <c...@rebertia.com>
Date: Thu, 2 Feb 2012 17:24:23 -0800
Local: Thurs, Feb 2 2012 8:24 pm
Subject: Re: multiple constructor __init__

I believe you can approximate that using a keyword-only argument
without a default value:

# Untested!
# Requires Python 3.x
class QObject(object):
    def __init__(self, param1=some_default, *, parent):
        # …

obj1 = QObject(parent=daddy)
obj2 = QObject(arg1, parent=daddy)

obj3 = QObject(daddy) # ERROR
obj4 = QObject(arg1, daddy) # ERROR
obj5 = QObject() # ERROR

Cheers,
Chris
--
Using names instead of some arbitrary ordering makes much more sense.
http://rebertia.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Terry Reedy  
View profile  
 More options Feb 2, 10:43 pm
Newsgroups: comp.lang.python
From: Terry Reedy <tjre...@udel.edu>
Date: Thu, 02 Feb 2012 22:43:16 -0500
Local: Thurs, Feb 2 2012 10:43 pm
Subject: Re: multiple constructor __init__
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »