curly-brace-aphobic?

Remco Gerlich scarblac at pino.selwerd.nl
Mon Jan 29 20:42:11 EST 2001


Rainer Deyke <root at rainerdeyke.com> wrote in comp.lang.python:
> None of these is really a compelling reason for using '[]' instead of '()'
> for access.  There is no efficiency difference in Python because both are
> implemented as (hidden) method calls, and languages like C++ allow 'f(5) =
> 5;'.  Is there any good reason for function calls to use a different syntax
> than mapping/sequence element access?

For one thing, it's possible to have an object that you can do both things
on, so the syntax should be different.

class Graph:
   def __getitem__(self, i):
      print "This column represents 30% of the population"
   def __call__(self, i):
      print "This column represents 50% *of the population!*"
      
x = Graph()
x[3]
x(3)

-- 
Remco Gerlich



More information about the Python-list mailing list