[Python] super(MyClass, self).__init__(*args, **kwargs)

Giuseppe Costanzi giuseppecostanzi a gmail.com
Mer 17 Feb 2016 21:22:30 CET


2016-02-17 21:20 GMT+01:00 Giuseppe Costanzi <giuseppecostanzi a gmail.com>:
> hai capito perfettamente,
> tra l' altro se seguo il consiglio di christian ottengo
> bc a hal9000:~/stimuli$ python super.py
> MRO: ['B', 'A', 'object']
> __init__ class B: (('Y', 'Y', 'Z'), {1: 'A', 2: 'B', 3: 'C'}) {}
> __init__ class A: (('Y', 'Y', 'Z'), {1: 'A', 2: 'B', 3: 'C'}) {}
> super class B: (('Y', 'Y', 'Z'), {1: 'A', 2: 'B', 3: 'C'}) {}
> class: B
> kwargs : {}
>
> sono a dir poco confuso
>
> 2016-02-17 20:57 GMT+01:00 Francesco Pischedda <francesco.pischedda a gmail.com>:
>>
>> 2016-02-17 19:59 GMT+01:00 Giuseppe Costanzi <giuseppecostanzi a gmail.com>:
>>>
>>> args = ('Y','Y','Z')
>>>     kwargs = {1:"A", 2:"B", 3:"C"}
>>>
>>>     foo = B(args, kwargs)
>>
>>
>> ok questo č praticamente un check della mia comprensione di questo
>> meccanismo di python:
>>
>> nella chiama al costruttore di B stai passando due argomenti posizionali
>> cioč args e kwargs che sono rispettivamente una tupla e un dict e il
>> __init__ di B ha un primo parametro posizionale chiamato arg (che cattura la
>> prima tupla) mentre mi pare di capire che tu volessi fare una cosa del tipo:
>>
>> foo = B(*args, **kwargs)
>>
>> cioč espandere la tupla args in parametri posizionali e il dict kwargs in
>> parametri chiave valore, ho capito male?
>>
>>
>> --
>> "Unix IS user friendly. It's just selective about who its friend are"
>>
>> "Nevertheless I still think it’s a bad idea to make things harder for
>> ourselves if we can avoid it."
>>
>> "C is quirky, flawed, and an enormous success."
>>                                    -- Dennis Ritchie
>>
>> "Shipping is a feature. A really important feature. Your product must have
>> it."
>>
>> "La gatta frettolosa ha fatto i gattini ciechi"
>>
>>
>> _______________________________________________
>> Python mailing list
>> Python a lists.python.it
>> http://lists.python.it/mailman/listinfo/python
>>

scusate il quoting....


Maggiori informazioni sulla lista Python