Re: Seemingly odd 'is' comparison.

2008-02-19 Thread Arnaud Delobelle
On Feb 19, 1:47 pm, Boris Borcic <[EMAIL PROTECTED]> wrote: > Arnaud Delobelle wrote: > > On Feb 13, 10:19 pm, Tobiah <[EMAIL PROTECTED]> wrote: > > print float(3.0) is float(3.0) > >> True > > print float(3.0 * 1.0) is float(3.0) > >> False > > > [You don't need to wrap your floats in floa

Re: Seemingly odd 'is' comparison.

2008-02-19 Thread Paul Rubin
Christian Heimes <[EMAIL PROTECTED]> writes: > >>> id(2000) > 3084440752 > >>> id(2001) > 3084440752 Python 2.4.4 (#1, Oct 23 2006, 13:58:00) >>> id(2000) 155211416 >>> id(2001) 155211416 >>> id(2000) == id(2001) False >From the docs: id( object) Return the ``ide

Re: Seemingly odd 'is' comparison.

2008-02-19 Thread Christian Heimes
Asun Friere wrote: > So was that a yes or no? I mean is it even possible for the identity > behaviour of mutables to vary between implementations? I can't see > how they can possibly be interned, but is there some other factor I'm > missing in regard to identity behaviour which could in fact vary

Re: Seemingly odd 'is' comparison.

2008-02-19 Thread Christian Heimes
Steven D'Aprano wrote: > "is" is a comparison operator: it compares identity, not equality. It is > more or less equivalent to the expression id(x) == id(y). Yes, the implementation of the is operator comes down to the comparison of PyObject* pointer addresses and in CPython id() returns the addr

Re: Seemingly odd 'is' comparison.

2008-02-19 Thread Boris Borcic
Duncan Booth wrote: > Boris Borcic <[EMAIL PROTECTED]> wrote: >> Arnaud Delobelle wrote: >>> Whereas when "3.0*1.0 is 3.0" is evaluated, *two* different float >>> objects are put on the stack and compared (LOAD_CONST 3 / LOAD_CONST >>> 1 / COMPARE_OP 8). Therefore the result is False. >> Looks goo

Re: Seemingly odd 'is' comparison.

2008-02-19 Thread Duncan Booth
Boris Borcic <[EMAIL PROTECTED]> wrote: > Arnaud Delobelle wrote: >> Whereas when "3.0*1.0 is 3.0" is evaluated, *two* different float >> objects are put on the stack and compared (LOAD_CONST 3 / LOAD_CONST >> 1 / COMPARE_OP 8). Therefore the result is False. > > Looks good, but doesn't pass the

Re: Seemingly odd 'is' comparison.

2008-02-19 Thread Boris Borcic
Arnaud Delobelle wrote: > On Feb 13, 10:19 pm, Tobiah <[EMAIL PROTECTED]> wrote: > print float(3.0) is float(3.0) >> True > print float(3.0 * 1.0) is float(3.0) >> False > > [You don't need to wrap your floats in float()] > def f(): > ... return 3.0 is 3.0, 3.0*1.0 is 3.0 > ... >

Re: Seemingly odd 'is' comparison.

2008-02-18 Thread Terry Reedy
"Asun Friere" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | So was that a yes or no? I mean is it even possible for the identity | behaviour of mutables to vary between implementations? I can't see | how they can possibly be interned, but is there some other factor I'm | missing

Re: Seemingly odd 'is' comparison.

2008-02-18 Thread Asun Friere
On Feb 19, 1:45 pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > "Asun Friere" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > | The advice not to identity test strings and numbers (since they are > | interred in the main implementation), > > They may or may not be. Obviously, and

Re: Seemingly odd 'is' comparison.

2008-02-18 Thread Terry Reedy
"Asun Friere" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | On Feb 19, 9:44 am, Steven D'Aprano <[EMAIL PROTECTED] | cybersource.com.au> wrote: | | > Except for documented singletons such as modules and None, which objects | > have the same identity is platform dependent, version

Re: Seemingly odd 'is' comparison.

2008-02-18 Thread Asun Friere
On Feb 19, 9:44 am, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > Except for documented singletons such as modules and None, which objects > have the same identity is platform dependent, version dependent, and even > dependent on the execution history of your code. The advice no

Re: Seemingly odd 'is' comparison.

2008-02-18 Thread Asun Friere
On Feb 19, 12:27 pm, Asun Friere <[EMAIL PROTECTED]> wrote: > But given the nature of immutables I meant to write "given the nature of mutables" of course ... :/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Seemingly odd 'is' comparison.

2008-02-18 Thread Asun Friere
On Feb 19, 9:44 am, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > Except for documented singletons such as modules and None, which objects > have the same identity is platform dependent, version dependent, and even > dependent on the execution history of your code. The advice no

Re: Seemingly odd 'is' comparison.

2008-02-18 Thread Steven D'Aprano
On Mon, 18 Feb 2008 14:11:53 +0100, Christian Heimes wrote: > Tobiah wrote: > print float(3.0) is float(3.0) >> True > print float(3.0 * 1.0) is float(3.0) >> False > > > Thumb rule: Never compare strings, numbers or tuples with "is". Only > compare an object with a singl

Re: Seemingly odd 'is' comparison.

2008-02-18 Thread Erik Max Francis
Tobiah wrote: print float(3.0) is float(3.0) > True print float(3.0 * 1.0) is float(3.0) > False It's implementation dependent what values these expressions will take. If you're trying to test equality, use `==`, not `is`. -- Erik Max Francis && [EMAIL PROTECTED] && http://

Re: Seemingly odd 'is' comparison.

2008-02-18 Thread Christian Heimes
Tobiah wrote: print float(3.0) is float(3.0) > True print float(3.0 * 1.0) is float(3.0) > False Thumb rule: Never compare strings, numbers or tuples with "is". Only compare an object with a singleton like a type or None. "is" is not a comparison operator. Christian -- http:

Re: Seemingly odd 'is' comparison.

2008-02-18 Thread Duncan Booth
Tobiah <[EMAIL PROTECTED]> wrote: > Subject: Seemingly odd 'is' comparison. Please put your question into the body of the message, not just the headers. >>>> print float(3.0) is float(3.0) > True >>>> print float(3.0 * 1.0) is float(3.0) > Fa

Re: Seemingly odd 'is' comparison.

2008-02-18 Thread Arnaud Delobelle
On Feb 13, 10:19 pm, Tobiah <[EMAIL PROTECTED]> wrote: > >>> print float(3.0) is float(3.0) > True > >>> print float(3.0 * 1.0) is float(3.0) > False [You don't need to wrap your floats in float()] >>> def f(): ... return 3.0 is 3.0, 3.0*1.0 is 3.0 ... >>> f() (True, False) >>> import dis >>>

Seemingly odd 'is' comparison.

2008-02-18 Thread Tobiah
>>> print float(3.0) is float(3.0) True >>> print float(3.0 * 1.0) is float(3.0) False >>> Thanks, Tobiah -- Posted via a free Usenet account from http://www.teranews.com -- http://mail.python.org/mailman/listinfo/python-list