[Python] Introspezione - Ottenere implicitamente una variabile della classe parent

Giorgio Zoppi giorgio.zoppi a gmail.com
Lun 14 Mar 2011 11:00:25 CET


Si ma ce una cosa che non mi torna. Come faccio a stampare?


Il 14 marzo 2011 10:00, Enrico Franchi <enrico.franchi a gmail.com> ha scritto:
> Giovanni Porcari wrote:
>>
>> dict( [ (m,getattr(myInstanceOrClass,m))for m in dir(myInstanceOrClass) if
>> callable(getattr(myInstanceOrClass,m))])
>
> Puoi togliere le parentesi quadre (direi Python > 2.4; non ho un 2.4 per
> provare).
>
> Piu' rapido ancora usare direttamente vars sull'oggetto classe.
> Ho messo dict, perche' su quel python ritorna un dictproxy e mi era scomodo
> da stampare ;)
>
> dict(vars(str))
> Out[8]:
> {'__add__': <slot wrapper '__add__' of 'str' objects>,
> ...
>  '__getitem__': <slot wrapper '__getitem__' of 'str' objects>,
>  '__getnewargs__': <method '__getnewargs__' of 'str' objects>,
> ...
>  '_formatter_parser': <method '_formatter_parser' of 'str' objects>,
>  'capitalize': <method 'capitalize' of 'str' objects>,
>  'center': <method 'center' of 'str' objects>,
>  'count': <method 'count' of 'str' objects>,
> ...
>  'lower': <method 'lower' of 'str' objects>,
>  'lstrip': <method 'lstrip' of 'str' objects>,
>  'partition': <method 'partition' of 'str' objects>,
> ...
>  'upper': <method 'upper' of 'str' objects>,
>  'zfill': <method 'zfill' of 'str' objects>}
>
>
> --
> .
> ..: -enrico-
>
> _______________________________________________
> Python mailing list
> Python a lists.python.it
> http://lists.python.it/mailman/listinfo/python
>



-- 
Quiero ser el rayo de sol que cada día te despierta
para hacerte respirar y vivir en me.
"Favola -Moda".


Maggiori informazioni sulla lista Python