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


Groups > comp.lang.python > #10319

Re: Trying to learn about metaclasses

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <kilka.hamsa@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'parameter': 0.05; 'interpreter': 0.07; 'python': 0.08; 'attribute': 0.09; 'to:name:python list': 0.09; 'inherited': 0.16; 'mangled': 0.16; 'metaclasses': 0.16; 'subject:Trying': 0.16; 'seems': 0.20; 'discussion': 0.22; 'header:In-Reply-To:1': 0.22; 'code': 0.24; 'noticed': 0.26; 'posted': 0.26; 'correct': 0.29; 'accessible': 0.29; 'example': 0.30; 'parent': 0.30; 'version': 0.30; 'class': 0.31; 'received:209.85.216.46': 0.31; 'received:mail- qw0-f46.google.com': 0.31; 'this.': 0.31; 'earlier': 0.32; 'too': 0.32; 'message-id:@gmail.com': 0.32; 'to:addr:python-list': 0.34; 'header:User-Agent:1': 0.34; 'there': 0.34; 'someone': 0.34; 'rule': 0.34; 'uses': 0.35; 'issue': 0.37; 'received:192': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.38; 'think': 0.38; 'form.': 0.39; 'to:addr:python.org': 0.39; 'received:209': 0.40; 'where': 0.40; 'excellent.': 0.84; 'subject:learn': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=h/U03XyRmo8WvvrgwGTdSgFwaIramrFxH4L/u8RQPnQ=; b=Yul55jykL5zbqWHE7lP0q7ufzrMXvLCtBiZMrK57N/WLt35hSPxT0lUCtejOfbPmaj 7Vv1jomlrKQpg6tdH7j60Nmb/m3gq0ufTwOOYDRPF3c9EPOGqxHxObqF4Eek7hLY6Hnk tc10nWrxHnxDSt0iu4gbwosL4tYCGE3TcjYBU=
Date Mon, 25 Jul 2011 22:44:17 -0400
From Victor Khangulov <kilka.hamsa@gmail.com>
User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.18) Gecko/20110616 Lightning/1.0b2 Thunderbird/3.1.11
MIME-Version 1.0
To python list <python-list@python.org>
Subject Re: Trying to learn about metaclasses
References <4E2D8D7F.60201@syslang.net>
In-Reply-To <4E2D8D7F.60201@syslang.net>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1483.1311648254.1164.python-list@python.org> (permalink)
Lines 18
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1311648254 news.xs4all.nl 23930 [2001:888:2000:d::a6]:35176
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:10319

Show key headers only | 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