Re: Overloading __init__ & Function overloading
- From: Paul Rubin <http://phr.cx@xxxxxxxxxxxxxx>
- Date: 30 Sep 2005 07:29:45 -0700
"Iyer, Prasad C" <prasad.c.iyer@xxxxxxxxxxxxx> writes:
> But I want to do something like this
>
> class BaseClass:
> def __init__(self):
> # Some code over here
> def __init__(self, a, b):
> # Some code over here
> def __init__(self, a, b, c):
> # some code here
You can only use one __init__ method. You'd have it count the args:
class BaseClass:
def __init__(self, *args):
if len(args) == 2:
a, b = args
# some code
elif len(args) == 3:
a, b, c = args
# more code
.
- Follow-Ups:
- Re: Overloading __init__ & Function overloading
- From: John J. Lee
- Re: Overloading __init__ & Function overloading
- References:
- RE: Overloading __init__ & Function overloading
- From: Iyer, Prasad C
- RE: Overloading __init__ & Function overloading
- Prev by Date: play audio on OSX?
- Next by Date: Re: [Info] PEP 308 accepted - new conditional expressions
- Previous by thread: RE: Overloading __init__ & Function overloading
- Next by thread: Re: Overloading __init__ & Function overloading
- Index(es):