Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: using __getitem()__ correctly Date: Thu, 31 Dec 2015 00:11:24 +1100 Lines: 28 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de 5zEcHjC5pXLJi8/T5n7F8Aym7RAaEQKXx0LCqRc1lIew== Return-Path: 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; 'received:209.85.223': 0.03; 'cc:addr:python-list': 0.09; 'any.': 0.09; 'caveat': 0.09; 'here?': 0.09; 'subject:()': 0.09; 'subject:using': 0.09; 'wed,': 0.15; 'brackets:': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'attribute': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'class,': 0.22; 'dec': 0.23; 'header:In-Reply-To:1': 0.24; 'least': 0.27; 'message-id:@mail.gmail.com': 0.27; 'post': 0.31; 'skip:_ 10': 0.32; 'anybody': 0.32; 'received:google.com': 0.35; "isn't": 0.35; 'but': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'thought': 0.37; '(with': 0.38; 'received:209': 0.38; 'why': 0.39; 'where': 0.40; 'called': 0.40; 'hello,': 0.40; 'your': 0.60; 'skip:u 10': 0.61; 'entire': 0.61; '30,': 0.63; 'subscript': 0.66; 'smith': 0.76; '(going': 0.84; 'chrisa': 0.84; 'to:none': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=gFp19vAgHzVdEd8gbKRWcNM8s3+xDpdUvagHERcODHI=; b=dCyEkeOajPLze/bbKCi6eEJWKaqnOd0cGX4ZA0OQhC4mJKB+/Xhy4sDEbqQUNYWieq OmG9y6x3HVQZZo0RLfIFGmm/O39tqkXgf4UJ9qRoB0vMM3AO6O8W3f/wK5oPNF8OmVBZ imA13kmV/J+fYz/OMLrusYNyrSU9SPYTMZt9eNtNM+NEYre3mGV7qw8+sJ1zOYMiAUyI qHpGMREd1GBbcof/5QHHOcLUzWGvlYOHWNGpGomyqLvTiFvmlzw3UomuiWmIG2ydEkmZ EqQC+Ehj3bpWMv/ijmtZIS84TZfw626GCexulDuyax+hhYvZZF0vBgrhqUkgOuJt/GSJ xNfw== X-Received: by 10.107.40.76 with SMTP id o73mr2835371ioo.157.1451481084690; Wed, 30 Dec 2015 05:11:24 -0800 (PST) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:100990 On Wed, Dec 30, 2015 at 11:57 PM, Charles T. Smith wrote: > Hello, > > I thought __getitem__() was invoked when an object is postfixed with an > expression in brackets: > > - abc[n] > > and __getattr__() was invoked when an object is postfixed with an dot: > > - abc.member That would be normal (with the caveat that __getattr__ is called only if the attribute isn't found; __getattribute__ is called unconditionally). > but my __getitem__ is being invoked at this time, where there's no > subscript (going into a spiral recursion death): > > self.mcc = self.attrs.mcc > > Can anybody explain to me why __getitem__() would be invoked here? Can you post your entire class, or at least __getattr__? Also check superclasses, if there are any. ChrisA