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__
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
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
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
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
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
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
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
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
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"
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
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
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
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)
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.
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
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
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.
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
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
20 matches
Mail list logo