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


Groups > comp.lang.python > #7457

Re: Square bracket and dot notations?

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Square bracket and dot notations?
Date 2011-06-11 15:49 -0400
References <4ab9f6bd-cf2d-4c0a-8eda-7d8ffa6bd6c4@v10g2000yqn.googlegroups.com> <801d330e-5610-45a3-ba5d-796e2ec179fe@w10g2000yqh.googlegroups.com> <c50676cd-622b-4c31-95c6-d2e01cd661ec@j23g2000yqc.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.135.1307821792.11593.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Square bracket and dot notations? Asen Bozhilov <asen.bozhilov@gmail.com> - 2011-06-11 02:41 -0700
  Re: Square bracket and dot notations? Andrew Berg <bahamutzero8825@gmail.com> - 2011-06-11 05:06 -0500
  Re: Square bracket and dot notations? Ben Finney <ben+python@benfinney.id.au> - 2011-06-11 20:11 +1000
  Re: Square bracket and dot notations? Francesco Bochicchio <bieffe62@gmail.com> - 2011-06-11 03:46 -0700
    Re: Square bracket and dot notations? Asen Bozhilov <asen.bozhilov@gmail.com> - 2011-06-11 07:40 -0700
      Re: Square bracket and dot notations? Terry Reedy <tjreedy@udel.edu> - 2011-06-11 15:49 -0400
        Re: Square bracket and dot notations? Asen Bozhilov <asen.bozhilov@gmail.com> - 2011-06-11 13:41 -0700

csiph-web