Je le code suivant:Pypy erreur spécifique
#!/usr/bin/env python
#!/usr/bin/env pypy
class my_components(object):
COMP0 = 0
COMP1 = 1
COMP1 = 2
__IGNORECOMP = -1
def attribute_dictionary(o):
d = { }
for attr in dir(o):
if attr[:2] != '__':
print o,attr
d[attr] = o.__getattribute__(o, attr)
return d
def main():
print attribute_dictionary(my_components)
if __name__ == '__main__':
main()
que j'utilise pour faire efficacement ENUM fantaisie en python.
Il fonctionne très bien en python, impressions:
<class '__main__.my_components'> COMP0
<class '__main__.my_components'> COMP1
<class '__main__.my_components'> _my_components__IGNORECOMP
{'COMP0': 0, 'COMP1': 2, '_my_components__IGNORECOMP': -1}
Cependant, quand je le lance avec pypy (passer deux premières lignes), il échoue avec:
<class '__main__.my_components'> COMP0
Traceback (most recent call last):
File "app_main.py", line 53, in run_toplevel
File "./pypy_Test.py", line 25, in <module>
main()
File "./pypy_Test.py", line 21, in main
print attribute_dictionary(my_components)
File "./pypy_Test.py", line 17, in attribute_dictionary
d[attr] = o.__getattribute__(o, attr)
TypeError: unbound method __getattribute__() must be called with my_components instance as first argument (got type instance instead)
Les idées seront les bienvenues .
-Merci
qui a fonctionné. Merci – vkontori