Trying to learn about metaclasses

Victor Khangulov kilka.hamsa at gmail.com
Mon Jul 25 22:44:17 EDT 2011


Hi Steven,

I too am just learning about metaclasses in Python and I found the 
example you posted to be excellent.

I played around with it and noticed that the issue seems to be the 
double-underscore in front of the fields (cls.__fields = {}).  If you 
change this parameter to use the single-underscore, the code works 
perfectly.

I think that because of the double-underscore, the name of the attribute 
"fields" gets mangled by the interpreter and is not inherited from the 
parent class in its accessible form.  Now, I am not sure if the code 
posted uses an earlier version of Python where these rule are different 
or if there is a more correct way to achieve this.  I will follow this 
discussion to see if someone has a better answer.

-victor



More information about the Python-list mailing list