Trying to learn about metaclasses

Thomas Jollans t at
Tue Jul 26 12:45:18 CEST 2011

On 26/07/11 04:44, Victor Khangulov wrote:
> 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.

Hate to disappoint you, but there never was a double underscore. (That
would be a problem, of course, but, as Peter pointed out, __init was the
actual problem)

> 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