[python-nl] extending classes

Ronald Oussoren ronaldoussoren at mac.com
Thu Apr 20 10:08:10 CEST 2006


On 20-apr-2006, at 9:45, Chris Niekel wrote:

> On Thu, Apr 20, 2006 at 02:07:15AM +0200, Guido Wesdorp wrote:
>> Syntax is super(<class>, <instance>), voorbeeld:
>
> Dat dacht ik ook, maar ik krijg een error.
>
>> def test3(test):
>>     def __init__(self):
>>         super(test3, self).__init__()
>
>>>> class test5(test):
> ...     def __init__(self):
> ...         super(test5,self).__init__()
> ...         print 'test5'
> ...
>>>> t = test5()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "<stdin>", line 3, in __init__
> TypeError: super() argument 1 must be type, not classobj
>
> En wat nou het verschil tussen een type en een classobj is, geen idee.
> Dit gaat fout in python 2.3 en 2.4

Super werkt alleen als de klasse een new-style klasse is. Dat houdt
in dit geval in dat test een subklasse van object moet zijn.

Ronald



More information about the Python-nl mailing list