Re: negative numbers are not equal...

2008-08-15 Thread Christian Heimes
ariel ledesma wrote: well, i'm glad i stumbled upon this detail early on (i only had to fix about one page of code)... i'll just stick to 'is' when it concerns checking if it is the *same* object (memorywise) instead of an *equivalent* one... just before wrapping up, the special methods __eq__

Re: negative numbers are not equal...

2008-08-15 Thread ariel ledesma
well, i'm glad i stumbled upon this detail early on (i only had to fix about one page of code)... i'll just stick to 'is' when it concerns checking if it is the *same* object (memorywise) instead of an *equivalent* one... just before wrapping up, the special methods __eq__ and __ne__ are called

Re: negative numbers are not equal...

2008-08-15 Thread Dan Lenski
On Fri, 15 Aug 2008 08:03:23 -0700, Carl Banks wrote: > On Aug 14, 4:42 pm, Christian Heimes <[EMAIL PROTECTED]> wrote: >> Integers >> between -5 and +256 are singletons as are some other objects like >> strings with one element or empty tuples. > > Not quite. > > Python 2.5.2 (r252:60911, May 2

Re: negative numbers are not equal...

2008-08-15 Thread Bruno Desthuilliers
Terry Reedy a écrit : Mel wrote: castironpi wrote: It would be nice to put together a really canonical case of the use of the 'is' comparison. FTSOA for the sake of argument, when do you use it? Why is it even in the language? My poster child use case is in a MUDD game. For instance, the

Re: negative numbers are not equal...

2008-08-15 Thread Terry Reedy
Mel wrote: castironpi wrote: It would be nice to put together a really canonical case of the use of the 'is' comparison. FTSOA for the sake of argument, when do you use it? Why is it even in the language? My poster child use case is in a MUDD game. For instance, the player represented by

Re: negative numbers are not equal...

2008-08-15 Thread Mel
castironpi wrote: > It would be nice to put together a really canonical case of the use of > the 'is' comparison. FTSOA for the sake of argument, when do you use > it? Why is it even in the language? My poster child use case is in a MUDD game. For instance, the player represented by `this_playe

Re: negative numbers are not equal...

2008-08-15 Thread Fredrik Lundh
castironpi wrote: This case actually misses handleC(). The solution is that the function that is returning '-10' cannot return -10, it has to return flagC. This can cause difficulties in cases when you're doing operations on flags. Worse, if flagC is nested somewhere, say moduleA.classB.flagC

Re: negative numbers are not equal...

2008-08-15 Thread Bruno Desthuilliers
castironpi a écrit : (snip) It would be nice to put together a really canonical case of the use of the 'is' comparison. FTSOA for the sake of argument, when do you use it? When I want to test objects identity. An idenity test is an identity test is an identity test is an Why is it eve

Re: negative numbers are not equal...

2008-08-15 Thread castironpi
On Aug 15, 8:56 am, Dan Lenski <[EMAIL PROTECTED]> wrote: > On Thu, 14 Aug 2008 17:18:55 -0300, ariel ledesma wrote: > > hello guys > > > i just ran into this when comparing negative numbers, they start > > returning False from -6 down, but only when comparing with 'is' > > >  >>> m = -5 > >  >>> a

Re: negative numbers are not equal...

2008-08-15 Thread Carl Banks
On Aug 14, 4:42 pm, Christian Heimes <[EMAIL PROTECTED]> wrote: > Integers > between -5 and +256 are singletons as are some other objects like > strings with one element or empty tuples. Not quite. Python 2.5.2 (r252:60911, May 28 2008, 08:35:32) [GCC 4.2.4 (Debian 4.2.4-1)] on linux2 Type "help"

Re: negative numbers are not equal...

2008-08-15 Thread Dan Lenski
On Thu, 14 Aug 2008 17:18:55 -0300, ariel ledesma wrote: > hello guys > > i just ran into this when comparing negative numbers, they start > returning False from -6 down, but only when comparing with 'is' > > >>> m = -5 > >>> a = -5 > >>> m is a > True > >>> m = -6 > >>> a = -6 > >>> m is

Re: negative numbers are not equal...

2008-08-15 Thread Steven D'Aprano
On Thu, 14 Aug 2008 20:44:32 -0700, castironpi wrote: > For > > a= 6 > b= a > > the test > > a is b > > should clearly return true. Since Python promises not to make a copy of a when you execute "b = a", then I think that such behaviour is guaranteed by the language. > Python distinguishes

Re: negative numbers are not equal...

2008-08-15 Thread Fredrik Lundh
ariel ledesma wrote: i see now, so i guess that's also why id() returns the same address for them as well... i'll dive into the implementation file, it may be a bit out of my league but i'll see what i can gather, and hey, that's how it works, right? :-) well, there's another strategy, of cou

Re: negative numbers are not equal...

2008-08-14 Thread castironpi
On Aug 14, 4:31 pm, Wojtek Walczak <[EMAIL PROTECTED]> wrote: > On Thu, 14 Aug 2008 18:23:21 -0300, ariel ledesma wrote: > > i see now, so i guess that's also why id() returns the same address for > > them as well... > > It just have to work like this. > > a is b > > is actually equal to: > > id(a)

Re: negative numbers are not equal...

2008-08-14 Thread Wojtek Walczak
On Thu, 14 Aug 2008 18:23:21 -0300, ariel ledesma wrote: > i see now, so i guess that's also why id() returns the same address for > them as well... It just have to work like this. a is b is actually equal to: id(a) == id(b) so there is no other way for id() in such case. Hope this helps.

Re: negative numbers are not equal...

2008-08-14 Thread Terry Reedy
When you ask the interpreter to create an immutable object with a particular value, it may at its discretion, to conserve space and possibly conserve time, return an existing object with that same value. This is documented somewhere in the reference. The result of comparing two 'different' o

Re: negative numbers are not equal...

2008-08-14 Thread ariel ledesma
Christian Heimes wrote: You are getting the result because Python optimized small integers. See http://svn.python.org/projects/python/trunk/Objects/intobject.c Integers between -5 and +256 are singletons as are some other objects like strings with one element or empty tuples. You must not rel

Re: negative numbers are not equal...

2008-08-14 Thread Christian Heimes
ariel ledesma wrote: i read that 'is' compares if they are really the same object, but i don't that's it because then why does -5 return True? of course i could only use == to compare, but still, what am i missing here? Rule of thumb: Never use 'is' with any kind of string or numeric object.

Re: negative numbers are not equal...

2008-08-14 Thread Josh English
On Aug 14, 1:18 pm, ariel ledesma <[EMAIL PROTECTED]> wrote: > hello guys > > i just ran into this when comparing negative numbers, they start > returning False from -6 down, but only when comparing with 'is' > >  >>> m = -5 >  >>> a = -5 >  >>> m is a > True >  >>> m = -6 >  >>> a = -6 >  >>> m is

negative numbers are not equal...

2008-08-14 Thread ariel ledesma
hello guys i just ran into this when comparing negative numbers, they start returning False from -6 down, but only when comparing with 'is' >>> m = -5 >>> a = -5 >>> m is a True >>> m = -6 >>> a = -6 >>> m is a False >>> m == a True i read that 'is' compares if they are really the same object