Keyword calling gotcha ?

Michael Hudson mwh21 at cam.ac.uk
Tue May 25 15:04:44 EDT 1999


"Darrell" <news at dorb.com> writes:
> Am I missing something ?

Yes.

> >>> class A:
> ...     def __init__(self, **parms):
> ...             pass
> ...
> >>> class B(A):
> ...     def __init__(self, **parms):
> ...             A.__init__(self,parms)

Try:

apply(A.__init__,(self,),parms)

Yes, it's ugly. I don't know any other way of doing it though.

HTH
Michael

> ...
> >>> A(a=1,b=2)
> <__main__.A instance at 7f85a0>
> >>>
> >>> B(a=1,b=2)
> Traceback (innermost last):
>   File "<stdin>", line 1, in ?
>   File "<stdin>", line 3, in __init__
> TypeError: too many arguments; expected 1, got 2
> >>>
> 
> --Darrell




More information about the Python-list mailing list