Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!87.79.20.101.MISMATCH!newsreader4.netcologne.de!news.netcologne.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python': 0.08; 'attribute': 0.09; 'either.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'error:': 0.12; 'wrote:': 0.15; 'attribute,': 0.16; 'bases,': 0.16; 'complains': 0.16; 'construct.': 0.16; 'dangerous,': 0.16; 'grateful.': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'subject:Trying': 0.16; 'def': 0.16; '(most': 0.21; "doesn't": 0.22; 'wrong?': 0.23; 'code': 0.24; 'traceback': 0.25; 'tried': 0.27; "i'm": 0.27; '27,': 0.29; 'object': 0.30; 'example': 0.30; 'from:addr:web.de': 0.30; 'class': 0.31; 'print': 0.32; 'it.': 0.33; 'to:addr:python-list': 0.34; 'header:X-Complaints-To:1': 0.34; 'someone': 0.34; 'quite': 0.34; 'starting': 0.35; 'last):': 0.35; 'running': 0.35; 'skip:" 10': 0.36; 'file': 0.36; 'page': 0.36; 'doing': 0.37; 'but': 0.37; 'received:org': 0.38; 'url:org': 0.38; 'subject:: ': 0.38; 'steven': 0.38; 'something': 0.38; 'think': 0.38; 'run': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; "i'd": 0.40; 'happen': 0.62; "'person'": 0.84; 'subject:learn': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Trying to learn about metaclasses Date: Mon, 25 Jul 2011 18:01:58 +0200 Organization: None References: <4E2D8D7F.60201@syslang.net> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084b8ef.dip.t-dialin.net X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1311609726 news.xs4all.nl 23852 [2001:888:2000:d::a6]:38465 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:10284 Steven W. Orr wrote: > I have been doing a lot of reading. I'm starting to get it. I think it's > really cool as well as dangerous, but I plan on being respectful of the > construct. I found a web page that I found quite readable. > > http://cleverdevil.org/computing/78/ > > So, I tried to run the example code (below), and I get AttributeError. If > someone can get me over this hump, I'd be grateful. It complains that > Person has no _fields attribute, but the print hello I have in > EnforcerMeta doesn't happen either. Am I doing something wrong? > > I'm running python 2.6.2 > > Here's the error: > > 585 > ./meta1.py > Traceback (most recent call last): > File "./meta1.py", line 38, in > swo.name = 'swo' > File "./meta1.py", line 27, in __setattr__ > if key in self._fields: > AttributeError: 'Person' object has no attribute '_fields' > And here's the code: > > class EnforcerMeta(type): > def __init(cls, name, bases, ns): You misspelt __init__()