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 []

2009-10-15 Thread Terry Reedy
SmokingDog wrote: > Interesting interpretation.. but I just gave it a try. > a = (1,2,3,4) a > (1, 2, 3, 4) a.index(3) > 2 a.index(5) > Traceback (most recent call last): > File "", line 1, in > ValueError: tuple.index(x): x not in tuple > > So my Python is say

Re: () vs []

2009-10-15 Thread Xavier Ho
On Thu, Oct 15, 2009 at 6:55 PM, Tim Golden wrote: > It was added relatively recently, around Python 2.6 I think, > at least partly as an oh-ok-then reaction to everyone asking: > "how come lists have .index and .count and tuples don't?" > and neverending "tuples-are-immutable-lists-no-they-aren'

Re: () vs []

2009-10-15 Thread Tim Golden
Xavier Ho wrote: On Thu, Oct 15, 2009 at 6:39 PM, Chris Rebert wrote: Nanjundi meant "index method" as in "a method .index()" (i.e. a method named "index") which searches through the container for the given item and returns the index of the first instance of said item, like list.index() does.

Re: () vs []

2009-10-15 Thread Chris Rebert
On Thu, Oct 15, 2009 at 1:46 AM, Xavier Ho wrote: > > On Thu, Oct 15, 2009 at 6:39 PM, Chris Rebert wrote: >> >> Nanjundi meant "index method" as in "a method .index()" (i.e. a method >> named "index") which searches through the container for the given item >> and returns the index of the first i

Re: () vs []

2009-10-15 Thread Xavier Ho
On Thu, Oct 15, 2009 at 6:39 PM, Chris Rebert wrote: > Nanjundi meant "index method" as in "a method .index()" (i.e. a method > named "index") which searches through the container for the given item > and returns the index of the first instance of said item, like > list.index() does. > > Interest

Re: () vs []

2009-10-15 Thread Chris Rebert
On Thu, Oct 15, 2009 at 1:27 AM, Xavier Ho wrote: > On Thu, Oct 15, 2009 at 3:21 AM, Nanjundi wrote: >> 3       You can’t find elements in a tuple. Tuples have no index method. > > I don't know what language you're using there, but my Python tuples have > indexes. > a = (1, 2, 3) a > (1

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 []

2009-10-15 Thread Xavier Ho
On Thu, Oct 15, 2009 at 3:21 AM, Nanjundi wrote: > 3 You can’t find elements in a tuple. Tuples have no index method. > I don't know what language you're using there, but my Python tuples have indexes. >>> a = (1, 2, 3) >>> a (1, 2, 3) >>> a[1] 2 -- http://mail.python.org/mailman/listinf

Re: () vs []

2009-10-15 Thread Nanjundi
On Oct 14, 1:05 pm, mattia wrote: > Any particular difference in using for a simple collection of element () > over [] or vice-versa? > > Thanks, Mattia From: http://www.faqs.org/docs/diveintopython/odbchelper_tuple.html 1 You can’t add elements to a tuple. Tuples have no append or extend

Re: () vs []

2009-10-15 Thread Mick Krippendorf
mattia schrieb: > Any particular difference in using for a simple collection of element () > over [] or vice-versa? Just try this and you'll see: tup = (1,2,3) tup.append(4) or: tup = (1,2,3) tup[0] = 4 HTH, Mick. -- http://mail.python.org/mailman/listinfo/python-list

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

Re: <> vs !=

2007-07-27 Thread Terry Reedy
"Simon Brunning" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | On 7/26/07, James Matthews <[EMAIL PROTECTED]> wrote: | > What is the difference between <> and != | | <> is deprecated, != isn't. Other than that, nothing AFAIK. And <> will disappear in 3.0. -- http://mail.pytho

Re: <> vs !=

2007-07-27 Thread Paul McGuire
On Jul 27, 7:35 am, Neil Cerutti <[EMAIL PROTECTED]> wrote: > > I like 'not ==', cf 'not in'. Sadly it's a syntax error. However, > as a language designer, I'm not > Guido. > I'd settle for == Guido myself. :) -- Paul -- http://mail.python.org/mailman/listinfo/python-list

Re: <> vs !=

2007-07-27 Thread Neil Cerutti
On 2007-07-27, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I believe Guido doesn't like '<>' and decided to enforce != > instead. Guess it's his language :). I like 'not ==', cf 'not in'. Sadly it's a syntax error. However, as a language designer, I'm not > Guido. -- Neil Cerutti I don't know

Re: <> vs !=

2007-07-27 Thread [EMAIL PROTECTED]
On Jul 27, 1:08 pm, "Simon Brunning" <[EMAIL PROTECTED]> wrote: > On 7/26/07, James Matthews <[EMAIL PROTECTED]> wrote: > > > What is the difference between <> and != > > <> is deprecated, != isn't. Other than that, nothing AFAIK. > > -- > Cheers, > Simon B. > [EMAIL PROTECTED]://www.brunningonline

Re: <> vs !=

2007-07-27 Thread Simon Brunning
On 7/26/07, James Matthews <[EMAIL PROTECTED]> wrote: > What is the difference between <> and != <> is deprecated, != isn't. Other than that, nothing AFAIK. -- Cheers, Simon B. [EMAIL PROTECTED] http://www.brunningonline.net/simon/blog/ GTalk: simon.brunning | MSN: small_values | Yahoo: smallval

Re: "re" vs "sre"?

2006-09-23 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Peter Otten wrote: > Lawrence D'Oliveiro wrote: > >> I learned about Python regular expressions from the Web documentation >> . This describes a module named >> "re". Then I saw some code written by a colleague, and he was using

Re: "re" vs "sre"?

2006-09-23 Thread Peter Otten
Lawrence D'Oliveiro wrote: > I learned about Python regular expressions from the Web documentation > . This describes a module named "re". > Then I saw some code written by a colleague, and he was using a module > named "sre". I checked my Python 2.4.3 installa

"re" vs "sre"?

2006-09-23 Thread Lawrence D'Oliveiro
I learned about Python regular expressions from the Web documentation . This describes a module named "re". Then I saw some code written by a colleague, and he was using a module named "sre". I checked my Python 2.4.3 installation, and sure enough, I have a modu

Re: RE vs. SRE

2005-08-21 Thread Michael Hoffman
Yoav wrote: > What is the difference between the two? Which on is better to use and why? In Python 2.4, this is what's in re.py: ''' """Minimal "re" compatibility wrapper. See "sre" for documentation.""" engine = "sre" # Some apps might use this undocumented variable from sre import * from sre

RE vs. SRE

2005-08-21 Thread Yoav
What is the difference between the two? Which on is better to use and why? Thanks. -- http://mail.python.org/mailman/listinfo/python-list