Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ben Finney Newsgroups: comp.lang.python Subject: Re: using __getitem()__ correctly Date: Thu, 31 Dec 2015 10:13:53 +1100 Lines: 27 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de QJ/YhMCoqzCwP6TtGxDlxQg1+TynbWl0QdBB7F21T+EA== Cancel-Lock: sha1:Gs1Batmy4vwUJVV+1Up+cZiv/WY= Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'collections': 0.09; 'exercising': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:()': 0.09; 'subject:using': 0.09; 'python': 0.10; 'translate': 0.15; 'attributes;': 0.16; 'dictionaries': 0.16; 'distinct': 0.16; 'distinction': 0.16; 'items;': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'smith"': 0.16; 'looked': 0.16; 'attribute': 0.18; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'key,': 0.29; 'methods.': 0.29; 'objects': 0.29; 'tutorial': 0.29; 'url:python': 0.33; 'languages': 0.34; 'important.': 0.35; 'quite': 0.35; 'url:org': 0.36; 'basic': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:org': 0.37; 'sure': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'some': 0.40; 'url:3': 0.60; "you'll": 0.61; 'skip:u 10': 0.61; 'real': 0.62; 'different': 0.63; 'between': 0.65; 'burden': 0.66; '8bit%:21': 0.70; 'special': 0.73; '1987': 0.84; '_o__)': 0.84; 'circles': 0.84; 'received:125': 0.84; 'url:tutorial': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: jigong.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) 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:101023 "Charles T. Smith" writes: > I don't understand this distinction between an "attribute" and a "dict > item". When did you most recently work through the Python tutorial > You may want to work through it again, from start to finish and exercising each example, to be sure you have a solid understanding of basic concepts like these. In brief: Objects have attributes; looking up an attribute on an object has specific syntax. Dictionaries are collections of items; the items are looked up by key, using a quite different syntax. Those two different syntaxes translate to distinct special methods. You may be familiar with other languages where the distinction between “attribute of an object” is not distinct from “item in a dictionary”. Python is not one of those languages; the distinction is real and important. You'll need to do some remedial learning of Python, and I recommend working through the Python tutorial. -- \ “But it is permissible to make a judgment after you have | `\ examined the evidence. In some circles it is even encouraged.” | _o__) —Carl Sagan, _The Burden of Skepticism_, 1987 | Ben Finney