[EMAIL PROTECTED] wrote:
>>Steve Holden wrote:
>>Consider:
>
>
> >>> a = {1:'one'}
> >>> b = {2:'two'}
> >>> c = {1:'one'}
> >>> a is c
> False
> >>> a in [b, c]
> True
> >>>
>
>
>>What would you have Python do differently in these circumstances?
>
>
> You mean: What i would do i if i w
> Steve Holden wrote:
>Consider:
>>> a = {1:'one'}
>>> b = {2:'two'}
>>> c = {1:'one'}
>>> a is c
False
>>> a in [b, c]
True
>>>
>What would you have Python do differently in these circumstances?
You mean: What i would do i if i was the benevolent dictator ?
I would make a distinction bet
[EMAIL PROTECTED] wrote:
> I understand this, Steve.
> I thought the _cmp_ method was a helper for sorting purposes. Why is it
> that a membership test needs to call the __cmp__ method?
Can you suggest another way to test for set membership, given that
instances aren't singletons? The only way to
[EMAIL PROTECTED] wrote:
> No doubt you're right but common sense dictates that membership testing
> would test identity not equality.
what does "common sense" have to say about this case:
>>> L = ("aa", "bb", "cc", "dd")
>>> S = "a" + "a"
>>> L
('aa', 'bb', 'cc', 'dd')
>>> S
'aa'
>>> S in L
# T
[EMAIL PROTECTED] wrote:
> No doubt you're right but common sense dictates that membership testing
> would test identity not equality.
> This is one of the rare occasions where Python defeats my common sense
But object identity is almost always a fairly ill-defined concept.
Consider this (Python
No doubt you're right but common sense dictates that membership testing
would test identity not equality.
This is one of the rare occasions where Python defeats my common sense
;-(
Alain
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
> In fact, i want to sort the list based on the 'allocated attribute' and
> at the same time, test membership based on the id attribute.
> __cmp__ logically implies an ordering test
really?
http://dictionary.reference.com/search?q=compare
com·pare
v. com·pare
[EMAIL PROTECTED] wrote:
> Sorry Fredrik but I don't understand. Just comment out the assert and
> you have different results depending on whether an unrelated sort
> function is defined.
> This seems weird to me !
code snippet:
> from random import choice
> class OBJ:
> def __init__(self,i
[EMAIL PROTECTED] wrote:
> In fact, i want to sort the list based on the 'allocated attribute' and
> at the same time, test membership based on the id attribute.
> __cmp__ logically implies an ordering test, not an identity test. These
> two notions seems to be confounded in python which is unfortu
On Fri, 2005-10-07 at 10:33, [EMAIL PROTECTED] wrote:
> In fact, i want to sort the list based on the 'allocated attribute' and
> at the same time, test membership based on the id attribute.
> __cmp__ logically implies an ordering test, not an identity test. These
> two notions seems to be confound
For this, you can also define the __eq__ method, which will be
preferred to __cmp__ for equallity tests while still using __cmp__ for
searching / comparisons.
--
http://mail.python.org/mailman/listinfo/python-list
In fact, i want to sort the list based on the 'allocated attribute' and
at the same time, test membership based on the id attribute.
__cmp__ logically implies an ordering test, not an identity test. These
two notions seems to be confounded in python which is unfortunate. Two
objects could have the
[EMAIL PROTECTED] wrote:
> Why is it that a membership test needs to call the __cmp__ method?
because the membership test has to check if the tested item is a member
of the sequence. if it doesn't do that, it's hardly qualifies as a membership
test. from the reference manual:
For the list a
Your __cmp__ method will always return 0, so all objects will be equal
when you add the method, as Simon and Steve pointed out. The result is
all objects will pass the test of being a member of excluded.
If you do not add a __cmp__ method objects will be compared on identy -
call the id() function
Your __cmp__ method will always return 0, so all objects will be equal
when you add the method, as Simon and Steve pointed out. The result is
all objects will pass the test of being a member of excluded.
If you do not add a __cmp__ method objects will be compared on identy -
call the id() function
[EMAIL PROTECTED] wrote:
> Sorry Fredrik but I don't understand. Just comment out the assert and
> you have different results depending on whether an unrelated sort
> function is defined.
>
> This seems weird to me !
not if you look at what it prints.
(if it seems weird to you that 0 equals 0, i
I understand this, Steve.
I thought the _cmp_ method was a helper for sorting purposes. Why is it
that a membership test needs to call the __cmp__ method?
If this isn't a bug, it is at least unexpected in my eyes.
Maybe a candidate for inclusion in the FAQ?
Thank you for answering
Alain
--
http:/
[EMAIL PROTECTED] wrote:
> Sorry Fredrik but I don't understand. Just comment out the assert and
> you have different results depending on whether an unrelated sort
> function is defined.
> This seems weird to me !
>
Perhaps you don't understand what's going on. The test
obj in excluded
is
Sorry Fredrik but I don't understand. Just comment out the assert and
you have different results depending on whether an unrelated sort
function is defined.
This seems weird to me !
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
> I came accross what i think is a serious bug in the python interpreter.
> Membership testing seems not to work for list of objects when these
> objects have a user-defined __cmp__ method.
it does not work if they have *your* __cmp__ method, no. if you add
a print stat
There is definitely a bug.
Maybe the follownig snippet is more clear:
class OBJ:
def __init__(self,identifier):
self.id=identifier
self.allocated=0
#def __cmp__(self,other):
# return cmp(other.allocated,self.allocated)
mylist=[OBJ(i) for
[EMAIL PROTECTED] wrote:
> Hello,
>
> I came accross what i think is a serious bug in the python interpreter.
>
> Membership testing seems not to work for list of objects when these
> objects have a user-defined __cmp__ method.
> It is present in Python 2.3 and 2.4. I don't know about other versi
Why would it be a bug? You've made it so that every instance of OBJ is
equal to every other instance of OBJ. The behaviour is as expected.
--
http://mail.python.org/mailman/listinfo/python-list
Hello,
I came accross what i think is a serious bug in the python interpreter.
Membership testing seems not to work for list of objects when these
objects have a user-defined __cmp__ method.
It is present in Python 2.3 and 2.4. I don't know about other versions.
The following code illustrates the
24 matches
Mail list logo