Re: () vs. [] operator

2009-10-15 Thread Carl Banks
On Oct 15, 12:14 am, Ole Streicher wrote: > Hi, > > I am curious when one should implement a "__call__()" and when a > "__getitem__()" method. > > For example, I want to display functions and data in the same plot. For > a function, the natural interface would to be called as "f(x)", while > the n

Re: () vs. [] operator

2009-10-15 Thread Ulrich Eckhardt
Ole Streicher wrote: > I am curious when one should implement a "__call__()" and when a > "__getitem__()" method. > > For example, I want to display functions and data in the same plot. Wait: The term 'function' is overloaded. In Python and programming in general, a function is a piece of code wi

Re: () vs. [] operator

2009-10-15 Thread Chris Rebert
On Thu, Oct 15, 2009 at 12:14 AM, Ole Streicher wrote: > Hi, > > I am curious when one should implement a "__call__()" and when a > "__getitem__()" method. > > For example, I want to display functions and data in the same plot. For > a function, the natural interface would to be called as "f(x)",

Re: () vs. [] operator

2009-10-15 Thread Xavier Ho
On Thu, Oct 15, 2009 at 5:14 PM, Ole Streicher wrote: > So what is the reason that Python has separate __call__()/() and > __getitem__()/[] interfaces and what is the rule to choose between them? Hi, This is very interesting, a thought that never occured to me before. Usually, a function is a

Re: () vs. [] operator

2009-10-15 Thread Steven D'Aprano
On Thu, 15 Oct 2009 09:14:35 +0200, Ole Streicher wrote: > So what is the reason that Python has separate __call__()/() and > __getitem__()/[] interfaces and what is the rule to choose between them? They are separate so you can implement both, or just one, or neither, whichever makes the most se

() vs. [] operator

2009-10-15 Thread Ole Streicher
Hi, I am curious when one should implement a "__call__()" and when a "__getitem__()" method. For example, I want to display functions and data in the same plot. For a function, the natural interface would to be called as "f(x)", while the natural interface for data would be "f[x]". On the other