Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'terry': 0.07; 'python': 0.08; 'collections': 0.09; 'dict': 0.09; 'hash': 0.09; 'notation.': 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; 'am,': 0.14; 'wrote:': 0.14; 'clash': 0.16; 'keys.': 0.16; 'meanwhile': 0.16; 'notations': 0.16; 'pythonic': 0.16; 'reedy': 0.16; 'underscore': 0.16; 'method.': 0.16; 'things.': 0.16; 'accessible': 0.19; 'jan': 0.20; 'header:In-Reply-To:1': 0.21; 'right.': 0.22; 'skip:[ 10': 0.26; 'classes': 0.26; 'not.': 0.26; 'object': 0.26; 'subject:?': 0.29; 'class': 0.29; "won't": 0.30; 'modules,': 0.30; 'parent': 0.30; 'tuples': 0.30; 'this.': 0.31; 'named': 0.32; 'header:X -Complaints-To:1': 0.32; 'someone': 0.33; 'to:addr:python-list': 0.33; 'thank': 0.35; 'there': 0.35; 'header:User-Agent:1': 0.35; 'yet,': 0.35; 'uses': 0.36; 'received:org': 0.38; 'could': 0.38; 'problem.': 0.38; 'but': 0.38; 'subject:: ': 0.38; 'some': 0.38; 'map': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'really': 0.40; 'you.': 0.62; 'other.': 0.63; 'property': 0.64; 'square': 0.67; 'here.': 0.69; 'examined': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Square bracket and dot notations? Date: Sat, 11 Jun 2011 15:49:36 -0400 References: <4ab9f6bd-cf2d-4c0a-8eda-7d8ffa6bd6c4@v10g2000yqn.googlegroups.com> <801d330e-5610-45a3-ba5d-796e2ec179fe@w10g2000yqh.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: rain.gmane.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10 In-Reply-To: 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: 27 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1307821792 news.xs4all.nl 49046 [::ffff:82.94.164.166]:33138 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7457 On 6/11/2011 10:40 AM, Asen Bozhilov wrote: > It is exactly what I wanted to know. Thank you. I have not examined > classes in Python yet, but when I do it I will understand some new > things. One of the most interesting is, can an object inherit items > trough the parent class? By items I mean items which are accessible > trough square bracket notation. .attributes are inherited. [index-or-key] items are not. > I really like Pythonic way here. Square bracket and dot notations > allow me to create an object which can be "true" hash map and > meanwhile to support independent methods from its keys. I could have > an item and a property with same names and they won't interfere each > other. Right. d.items is a dict method. d['items'] is whatever you assign. Named tuples in the collections modules, which allow access to fields through .name as well as [index], have the name class problem. All the methods are therefore given leading underscore names to avoid this. [But there still could be a clash if someone used field names with leading underscores!] Python reserves and uses __xxx__ for system names just to avoid clashes. -- Terry Jan Reedy