[Tutor] Calling super classs __init__?
Kent Johnson
kent37 at tds.net
Wed Mar 19 03:33:57 CET 2008
Allen Fowler wrote:
> What's the most "pythonic" way to make this work?
>
> class MySuperClass(object):
>
> def __init__(self, opt_1, opt_2, opt_3, opt_n):
> # stuff done here
> pass
>
>
> class MySubClass(MySuperClass):
>
> def __init__(self, just_a_sub_option): # what about other args? **args?
I think I would go ahead and list the superclass parameters and put the
new one at the end:
def __init__(self, opt_1, opt_2, opt_3, opt_n, just_a_sub_option):
> MySuperClass.__init__() # Should this be first? What args to use? **args?
MySuperClass.__init__(self, opt_1, opt_2, opt_3, opt_n)
John's method will also work but I prefer to add the new parameter at
the end of the argument list.
Kent
More information about the Tutor
mailing list