Re: Interpreter Bug

2021-06-02 Thread Barry Scott
> On 2 Jun 2021, at 10:34, Alice Braim wrote: > > Good morning- > > > > I am having some very serious issues with Python, and I was hoping you > could help? > > I downloaded both Python and PyCharm, and the 2 do not seem to be working. > Every time I select Python as an interpret

Interpreter Bug

2021-06-02 Thread Alice Braim
Good morning- I am having some very serious issues with Python, and I was hoping you could help? I downloaded both Python and PyCharm, and the 2 do not seem to be working. Every time I select Python as an interpreter, the whole thing crashes. Obviously, I went onto repairs, bu

Re: Python interpreter bug

2005-10-07 Thread Steve Holden
[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

Re: Python interpreter bug

2005-10-07 Thread alainpoint
> 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

Re: Python interpreter bug

2005-10-07 Thread Steve Holden
[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

Re: Python interpreter bug

2005-10-07 Thread Fredrik Lundh
[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

Re: Python interpreter bug

2005-10-07 Thread Christopher Subich
[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

Re: Python interpreter bug

2005-10-07 Thread alainpoint
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

Re: Python interpreter bug

2005-10-07 Thread Fredrik Lundh
[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

Re: Python interpreter bug

2005-10-07 Thread bruno modulix
[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

Re: Python interpreter bug

2005-10-07 Thread Robert Kern
[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

Re: Python interpreter bug

2005-10-07 Thread Carsten Haese
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

Re: Python interpreter bug

2005-10-07 Thread [EMAIL PROTECTED]
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

Re: Python interpreter bug

2005-10-07 Thread alainpoint
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

Re: Python interpreter bug

2005-10-07 Thread Fredrik Lundh
[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

Re: Python interpreter bug

2005-10-07 Thread [EMAIL PROTECTED]
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

Re: Python interpreter bug

2005-10-07 Thread [EMAIL PROTECTED]
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

Re: Python interpreter bug

2005-10-07 Thread Fredrik Lundh
[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

Re: Python interpreter bug

2005-10-07 Thread alainpoint
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:/

Re: Python interpreter bug

2005-10-07 Thread Steve Holden
[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

Re: Python interpreter bug

2005-10-07 Thread alainpoint
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

Re: Python interpreter bug

2005-10-07 Thread Fredrik Lundh
[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

Re: Python interpreter bug

2005-10-07 Thread alainpoint
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

Re: Python interpreter bug

2005-10-07 Thread Steve Holden
[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

Re: Python interpreter bug

2005-10-07 Thread Simon Percivall
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

Python interpreter bug

2005-10-07 Thread alainpoint
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