curly-brace-aphobic?

Greg Ewing greg at cosc.canterbury.ac.nz
Wed Jan 31 23:19:10 EST 2001


Grant Griffin wrote:
> 
> However, the rule that I seem to want to apply is "All indexers are indexed
> using the style of brace used to bind them."

But tuples and strings aren't constructed using any
kind of brackets at all:

   t = 1,2,3
   s = "parrot"

How do you propose to index those, using your rule?

What's more, there are many more indexable things than
the built-in ones. Extension modules can implement new
indexable types, and any class can be made indexable
by giving it a __getitem__ method.

If you want to index every indexable thing using a
unique syntax, you're going to run out of characters
very quickly!

It could be argued, I suppose, that sequence-like
objects should be indexed with [] and mapping-like
objects with {}. But is a class which has __getitem__
a sequence or a mapping? 

You could say that there should be two methods, such as 
__getitem__ for [] and __mapitem__ for {}. But that 
seems like needlessly multiplying entities. Why go to
all that trouble to provide two different indexing
notations when one is quite sufficient?

-- 
Greg Ewing, Computer Science Dept, University of Canterbury,	  
Christchurch, New Zealand
To get my email address, please visit my web page:	  
http://www.cosc.canterbury.ac.nz/~greg



More information about the Python-list mailing list