id == vs is

2014-10-26 Thread Dan Stromberg
Are the following two expressions the same? x is y Id(x) == id(y) ? I ported some Java code to Python, and it was using Java's idea of equality (via ==) in some places. Right now, I have a suite of unit tests working using the second expression above, but I'm thinking about switching to the fi

Re: id == vs is

2014-10-26 Thread MRAB
On 2014-10-27 00:12, Dan Stromberg wrote: Are the following two expressions the same? x is y Id(x) == id(y) ? Yes. I ported some Java code to Python, and it was using Java's idea of equality (via ==) in some places. Right now, I have a suite of unit tests working using the second expressi

Re: id == vs is

2014-10-26 Thread Joshua Landau
On 27 October 2014 00:12, Dan Stromberg wrote: > Are the following two expressions the same? > > x is y > > Id(x) == id(y) Much of the time, but not all the time. The obvious exception is if "id" is redefined, but that one's kind of boring. The real thing to watch out for is if the object that "x

Re: id == vs is

2014-10-26 Thread Ethan Furman
On 10/26/2014 05:23 PM, Ethan Furman wrote: On 10/26/2014 05:12 PM, Dan Stromberg wrote: Are the following two expressions the same? x is y Id(x) == id(y) ? Listen to MRAB, ignore me. That is all. -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list

Re: id == vs is

2014-10-26 Thread Ethan Furman
On 10/26/2014 05:12 PM, Dan Stromberg wrote: Are the following two expressions the same? x is y Id(x) == id(y) ? Nope. If the value if `id(x)` is not interned, then the two value could be different objects that still represent the same value. -- ~Ethan~ -- https://mail.python.org/mailman

Re: id == vs is

2014-10-26 Thread MRAB
On 2014-10-27 00:24, Ethan Furman wrote: On 10/26/2014 05:23 PM, Ethan Furman wrote: On 10/26/2014 05:12 PM, Dan Stromberg wrote: Are the following two expressions the same? x is y Id(x) == id(y) ? Listen to MRAB, ignore me. That is all. Well, apart of Joshua's qualifications, that is!

Re: id == vs is

2014-10-26 Thread Ben Finney
Dan Stromberg writes: > Are the following two expressions the same? > > x is y > > Id(x) == id(y) It depends what you mean by “the same”. Do they give the same result? Sometimes yes, sometimes no. It depends on what the types of the values are. Do they express the same intent? Always no. The f

Re: id == vs is

2014-10-26 Thread Denis McMahon
On Sun, 26 Oct 2014 17:12:29 -0700, Dan Stromberg wrote: > Are the following two expressions the same? > > x is y > > Id(x) == id(y) No, although if "Id" and "id" were the same function, they might be equivalent in some cases. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.pyth

Re: id == vs is

2014-10-26 Thread Cameron Simpson
On 27Oct2014 00:41, MRAB wrote: On 2014-10-27 00:24, Ethan Furman wrote: On 10/26/2014 05:23 PM, Ethan Furman wrote: On 10/26/2014 05:12 PM, Dan Stromberg wrote: Are the following two expressions the same? x is y Id(x) == id(y) ? Listen to MRAB, ignore me. That is all. Well, apart of J

Re: id == vs is

2014-10-26 Thread Ben Finney
Ben Finney writes: > Dan Stromberg writes: > > Are the following two expressions the same? […] > > It depends what you mean by “the same”. My apologies, I mis-read the question. My answers were for a different question (one you didn't ask). Please ignore that. -- \ “If you ever reach to

Re: id == vs is

2014-10-27 Thread Roy Smith
In article , Cameron Simpson wrote: > The "is" test is more direct and less subject to iffiness because the longer > expression using id() leaves more scope/time for things to change, and of > course "id" itself can be rebound to something weird. Not to mention that Python is case-sensitive a