Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #10319

Re: Trying to learn about metaclasses

Date 2011-07-25 22:44 -0400
From Victor Khangulov <kilka.hamsa@gmail.com>
Subject Re: Trying to learn about metaclasses
References <4E2D8D7F.60201@syslang.net>
Newsgroups comp.lang.python
Message-ID <mailman.1483.1311648254.1164.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Trying to learn about metaclasses Victor Khangulov <kilka.hamsa@gmail.com> - 2011-07-25 22:44 -0400

csiph-web