FAQ
2013/8/14 climb65 <climb65@laposte.net>

Hello,

here is a small basic question :

Is it possible to have more than one constructor (__init__ function) in a
class? For instance, to create an object with 2 different ways? If my
memory is good, I think that with C++ it is possible.

Thanks for your answer.
--
http://mail.python.org/mailman/listinfo/python-list





Hello,


You have to use default values in __init__ function, like :
def __init__( self, name = None ):
         self.name_ = name


and afterwards in your code, test variable :
if self.name_:
        do something...


Regards,
Phil.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130814/74c8f152/attachment.html>

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 7 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedAug 14, '13 at 2:16p
activeAug 15, '13 at 1:00p
posts7
users7
websitepython.org

People

Translate

site design / logo © 2022 Grokbase