On Thu, 12 Aug 2010 19:52:07 -0700, Matt Schinckel wrote:
a = "hello"
b = "hello"
a is b
> True
>
> Ooh, that looks dangerous. Are they the same object?
You don't need another test to know that they are the same object. The
`is` operator does exactly that: a is b *only* if a and
On 8/12/2010 10:52 PM, Matt Schinckel wrote:
a = "hello"
b = "hello"
a is b
True
Ooh, that looks dangerous.
Only for mutable objects
Are they the same object?
Yes.
a += "o"
This is equivalent to a = a+"o". The expression creates a new object.
The assignment binds the object to name
On Aug 6, 8:15 am, "Rhodri James" wrote:
> On Thu, 05 Aug 2010 17:07:53 +0100, wheres pythonmonks
>
> wrote:
> > Well, I am not convinced of the equivalence of not None and true:
[snip]
> >>> "spam, eggs, chips and spam" is "spam, eggs, chips and spam"
> True
> >>> a = "spam, eggs, chips and sp
Ben Finney wrote:
Peter Pearson writes:
Hey, that's a cute example, but . . . what a trap! Is it possible to
document the use-the-object-not-the-string requirement loudly enough
that people won't get caught?
Don't use strings for such values. The data isn't going to be used, so
there
"saeed.gnu" writes:
> "x is y" means "id(y) == id(y)"
> "x is not y" means "id(x) != id(x)"
> "x is not None" means "id(x) != id(None)"
No, the meanings are different. The behaviour might, or might not, be
the same. The operators are different *because* the meanings are
dif
On 08/09/2010 06:11 AM, saeed.gnu wrote:
> On Aug 9, 3:41 pm, "saeed.gnu" wrote:
>> "x is y" means "id(y) == id(y)"
>> "x is not y" means "id(x) != id(x)"
>> "x is not None" means "id(x) != id(None)"
>>
>> "x is not None" is a really silly statement!! because id(None) and id
En Mon, 09 Aug 2010 08:41:23 -0300, saeed.gnu
escribió:
"x is y" means "id(y) == id(y)"
"x is not y" means "id(x) != id(x)"
No; consider this:
py> id([])==id([])
True
py> [] is []
False
Comparing id's is the same as using the is operator only if you can
guarantee that
On 8/9/2010 7:41 AM, saeed.gnu wrote:
"x is y" means "id(y) == id(y)"
"x is not y" means "id(x) != id(x)"
"x is not None" means "id(x) != id(None)"
"x is not None" is a really silly statement!!
Wrong. It is exactly right when that is what one means and is the
STANDARD I
On Mon, 09 Aug 2010 04:41:23 -0700, saeed.gnu wrote:
> "x is not None" is a really silly statement!! because id(None) and id
> of any constant object is not predictable! I don't know whay people
> use "is" instead of "==". you should write "if x!=None" instead of "x
> is not None"
No, you should
saeed.gnu wrote:
On Aug 9, 3:41 pm, "saeed.gnu" wrote:
"x is y" means "id(y) =id(y)"
"x is not y" means "id(x) !=d(x)"
"x is not None" means "id(x) !=d(None)"
"x is not None" is a really silly statement!! because id(None) and id
of any constant object is not predictab
On Aug 9, 3:41 pm, "saeed.gnu" wrote:
> "x is y" means "id(y) == id(y)"
> "x is not y" means "id(x) != id(x)"
> "x is not None" means "id(x) != id(None)"
>
> "x is not None" is a really silly statement!! because id(None) and id
> of any constant object is not predictable! I
"x is y" means "id(y) == id(y)"
"x is not y" means "id(x) != id(x)"
"x is not None" means "id(x) != id(None)"
"x is not None" is a really silly statement!! because id(None) and id
of any constant object is not predictable! I don't know whay people
use "is" instead of "==". y
Gregory Ewing a écrit :
Ethan Furman wrote:
Instead of using 'is' use '=='. Maybe not as cute, but definitely
more robust!
It's also just as efficient if you use strings that
resemble identifiers, because they will be interned,
Remember : this IS an implementation detail.
--
http://mail.p
On 05Aug2010 12:07, wheres pythonmonks wrote:
| P.S. Sorry for the top-post -- is there a way to not do top posts from
| gmail? I haven't used usenet since tin.
The standard way is with attitude: view having your cursor at the top
not as forcing you to top post but as an opportunity to start pru
In article <8c2uiufg9...@mid.individual.net>,
Peter Pearson wrote:
>On Fri, 06 Aug 2010 15:37:04 +0200, Stefan Schwarzer wrote:
>[snip]
>> I can imagine a case where you might want to compare a
>> string with `is`:
>>
>> FORWARD = "forward"
>> BACKWARD = "backward"
>>
>> ...
>>
>>
Hi Ben,
On 2010-08-08 01:16, Ben Finney wrote:
> Don't use strings for such values. The data isn't going to be used, so
> there's no sense using a semantically rich data type like a string.
>
> Instead, use an ‘object’ instance; then, the only way to get a binding
> that will compare equal is to
Peter Pearson writes:
> Hey, that's a cute example, but . . . what a trap! Is it possible to
> document the use-the-object-not-the-string requirement loudly enough
> that people won't get caught?
Don't use strings for such values. The data isn't going to be used, so
there's no sense using a sema
On 08/07/2010 09:44 AM, Gabriel Genellina wrote:
> En Sat, 07 Aug 2010 04:04:06 -0300, Stefan Schwarzer
> escribió:
>> On 2010-08-07 00:28, Steven D'Aprano wrote:
>
>>> Actually, yes, equality is implemented with a short-cut
> that checks for
>>> identity first. That makes something like:
>>> [..
On Sat, 07 Aug 2010 14:28:19 +1000, Ben Finney wrote:
> Steven D'Aprano writes:
>
>> On Thu, 05 Aug 2010 12:07:53 -0400, wheres pythonmonks wrote:
>>
>> > P.S. Sorry for the top-post -- is there a way to not do top posts
>> > from gmail? I haven't used usenet since tin.
>>
>> Er, surely you can
En Sat, 07 Aug 2010 04:04:06 -0300, Stefan Schwarzer
escribió:
On 2010-08-07 00:28, Steven D'Aprano wrote:
Actually, yes, equality is implemented with a short-cut
that checks for
identity first. That makes something like:
[...]
Oops, I didn't realize that the OP had mentioned the
identit
Hi Steven,
On 2010-08-07 00:28, Steven D'Aprano wrote:
> On Fri, 06 Aug 2010 15:37:04 +0200, Stefan Schwarzer wrote:
>>> Plus, I believe the
>>> "==" operator will check if the variables point to the same object.
>>
>> No, that's what `is` is for.
>
> Actually, yes, equality is implemented with a
Steven D'Aprano writes:
> On Thu, 05 Aug 2010 12:07:53 -0400, wheres pythonmonks wrote:
>
> > P.S. Sorry for the top-post -- is there a way to not do top posts
> > from gmail? I haven't used usenet since tin.
>
> Er, surely you can just move the cursor before you start typing???
I like to think
Steven D'Aprano wrote:
Generally,
when testing for None, you actually want None and not some look-alike
that merely tests equal to None.
That's true, although I can't think of a use case for an object
that compares equal to None but isn't -- except for obfuscated
code competition entries and m
Ethan Furman wrote:
Instead of using 'is' use '=='. Maybe not as cute, but definitely more
robust!
It's also just as efficient if you use strings that
resemble identifiers, because they will be interned,
so the comparison will end up just doing an indentity
test anyway.
--
Greg
--
http://mai
On Fri, 06 Aug 2010 11:42:39 +0200, Jean-Michel Pichavant wrote:
> Steven D'Aprano wrote:
>> On Thu, 05 Aug 2010 12:07:53 -0400, wheres pythonmonks wrote:
>>
>>> P.S. Sorry for the top-post -- is there a way to not do top posts from
>>> gmail? I haven't used usenet since tin.
>>>
>> Er, sure
On Fri, 06 Aug 2010 15:37:04 +0200, Stefan Schwarzer wrote:
>> Plus, I believe the
>> "==" operator will check if the variables point to the same object.
>
> No, that's what `is` is for.
Actually, yes, equality is implemented with a short-cut that checks for
identity first. That makes something
On Fri, 06 Aug 2010 05:28:40 -0700, DG wrote:
> I've always thought of it as you don't compare strings with "is", you
> *should* use == The reasoning is that you don't know if that string
> instance is the only one in memory.
This is excellent advice. I won't say that there is "never" a use-case
On Fri, 06 Aug 2010 17:20:30 +, Peter Pearson wrote:
> On Fri, 06 Aug 2010 15:37:04 +0200, Stefan Schwarzer wrote: [snip]
>> I can imagine a case where you might want to compare a string with
>> `is`:
>>
>> FORWARD = "forward"
>> BACKWARD = "backward"
[...]
>> Actually, I've never seen
Stefan Schwarzer wrote:
Hello Peter,
On 2010-08-06 19:20, Peter Pearson wrote:
On Fri, 06 Aug 2010 15:37:04 +0200, Stefan Schwarzer wrote:
[snip]
I can imagine a case where you might want to compare a
string with `is`:
FORWARD = "forward"
BACKWARD = "backward"
...
def func(d
Hello Peter,
On 2010-08-06 19:20, Peter Pearson wrote:
> On Fri, 06 Aug 2010 15:37:04 +0200, Stefan Schwarzer wrote:
> [snip]
>> I can imagine a case where you might want to compare a
>> string with `is`:
>>
>> FORWARD = "forward"
>> BACKWARD = "backward"
>>
>> ...
>>
>> def func(d
On 8/6/2010 5:27 AM, Richard D. Moores wrote:
So there would be a different implementation for each operating
system? One for Windows, one for linux? Or one for Vista and one for
XP? I'm just trying to clarify what is meant by "implementation".
Different version of CPython (that string cachin
On Fri, 06 Aug 2010 15:37:04 +0200, Stefan Schwarzer wrote:
[snip]
> I can imagine a case where you might want to compare a
> string with `is`:
>
> FORWARD = "forward"
> BACKWARD = "backward"
>
> ...
>
> def func(direction=FORWARD):
> if direction is FORWARD:
> .
Hi DG,
On 2010-08-06 14:28, DG wrote:
> I've always thought of it as you don't compare strings with "is", you
> *should* use == The reasoning is that you don't know if that string
> instance is the only one in memory. I've heard as an implementation
> detail, since strings are immutable, that Py
On Aug 6, 2:32 am, Bruno Desthuilliers wrote:
> Richard D. Moores a écrit :
>
>
>
> > On Thu, Aug 5, 2010 at 16:15, Rhodri James
> > wrote:
> >> On Thu, 05 Aug 2010 17:07:53 +0100, wheres pythonmonks
> >> wrote:
>
> >> You're not testing for equivalence there, you're testing for identity.
> >
Richard D. Moores wrote:
> So there would be a different implementation
for each operating
> system? One for Windows, one for linux? Or one for
Vista and one for
> XP? I'm just trying to clarify what is meant by
"implementation".
there are dozillions of "implementation" of python: one
for each r
On Aug 6, 2010, at 9:25 AM, Bruno Desthuilliers wrote:
Roald de Vries a écrit :
'not None' first casts None to a bool, and then applies 'not', so
'x is not None' means 'x is True'.
Obviously plain wrong :
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help"
Steven D'Aprano wrote:
On Thu, 05 Aug 2010 12:07:53 -0400, wheres pythonmonks wrote:
P.S. Sorry for the top-post -- is there a way to not do top posts from
gmail? I haven't used usenet since tin.
Er, surely you can just move the cursor before you start typing???
CTRL+END will b
On Fri, Aug 6, 2010 at 01:32, Bruno Desthuilliers
wrote:
> Richard D. Moores a écrit :
>>
>> On Thu, Aug 5, 2010 at 16:15, Rhodri James
>> wrote:
>>>
>>> On Thu, 05 Aug 2010 17:07:53 +0100, wheres pythonmonks
>>> wrote:
>>
>>> You're not testing for equivalence there, you're testing for identity
Richard D. Moores a écrit :
On Thu, Aug 5, 2010 at 16:15, Rhodri James wrote:
On Thu, 05 Aug 2010 17:07:53 +0100, wheres pythonmonks
wrote:
You're not testing for equivalence there, you're testing for identity. "is"
and "is not" test whether the two objects concerned are (or are not) the
s
Roald de Vries a écrit :
'not None' first casts None to a bool, and then applies 'not', so 'x is
not None' means 'x is True'.
Obviously plain wrong :
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more informat
On Thu, Aug 5, 2010 at 16:15, Rhodri James wrote:
> On Thu, 05 Aug 2010 17:07:53 +0100, wheres pythonmonks
> wrote:
> You're not testing for equivalence there, you're testing for identity. "is"
> and "is not" test whether the two objects concerned are (or are not) the
> same object. Two object
On Thu, 05 Aug 2010 12:07:53 -0400, wheres pythonmonks wrote:
> P.S. Sorry for the top-post -- is there a way to not do top posts from
> gmail? I haven't used usenet since tin.
Er, surely you can just move the cursor before you start typing???
--
Steven
--
http://mail.python.org/mailman/lis
On Thu, 05 Aug 2010 17:07:53 +0100, wheres pythonmonks
wrote:
Well, I am not convinced of the equivalence of not None and true:
not None
True
3 is True;
False
3 is not None
True
You're not testing for equivalence there, you're testing for identity.
"is" and "is not" test whether
On Thu, Aug 5, 2010 at 9:07 AM, wheres pythonmonks
wrote:
> Well, I am not convinced of the equivalence of not None and true:
>
not None
> True
3 is True;
> False
3 is not None
> True
>
> P.S. Sorry for the top-post -- is there a way to not do top posts from
> gmail? I haven't
Roald de Vries wrote:
On Aug 5, 2010, at 5:42 PM, wheres pythonmonks wrote:
How does "x is not None" make any sense? "not x is None" does make
sense.
I can only surmise that in this context (preceding is) "not" is not a
unary right-associative operator, therefore:
x is not None === IS_NOTEQ(
Roald de Vries wrote:
On Aug 5,
2010, at 5:42 PM, wheres pythonmonks wrote:
How does "x is not None" make any sense? "not x is None" does make
sense.
I can only surmise that in this context (preceding is) "not" is not a
unary right-associative operator, therefore:
x is not None === IS_NOTEQ(
On Aug 5, 2010, at 6:11 PM, Chris Rebert wrote:
On Thu, Aug 5, 2010 at 8:56 AM, Roald de Vries
wrote:
On Aug 5, 2010, at 5:42 PM, wheres pythonmonks wrote:
How does "x is not None" make any sense? "not x is None" does
make sense.
I can only surmise that in this context (preceding is) "not
On Thu, Aug 5, 2010 at 8:42 AM, wheres pythonmonks
wrote:
> How does "x is not None" make any sense? "not x is None" does make sense.
>
> I can only surmise that in this context (preceding is) "not" is not a
> unary right-associative operator, therefore:
>
> x is not None === IS_NOTEQ(X, None)
>
On Thu, Aug 5, 2010 at 8:56 AM, Roald de Vries wrote:
> On Aug 5, 2010, at 5:42 PM, wheres pythonmonks wrote:
>> How does "x is not None" make any sense? "not x is None" does make sense.
>>
>> I can only surmise that in this context (preceding is) "not" is not a
>> unary right-associative operato
On Thu, Aug 5, 2010 at 8:42 AM, wheres pythonmonks
wrote:
> How does "x is not None" make any sense? "not x is None" does make sense.
>
> I can only surmise that in this context (preceding is) "not" is not a
> unary right-associative operator, therefore:
>
> x is not None === IS_NOTEQ(X, None)
>
Well, I am not convinced of the equivalence of not None and true:
>>> not None
True
>>> 3 is True;
False
>>> 3 is not None
True
>>>
P.S. Sorry for the top-post -- is there a way to not do top posts from
gmail? I haven't used usenet since tin.
On Thu, Aug 5, 2010 at 11:56 AM, Roald de Vries wro
wheres pythonmonks writes:
> How does "x is not None" make any sense?
In two ways: partly from the fact that Python syntax is preferentially
designed to be reasonably readable to a native English reader; and
partly because it makes for more obvious semantics.
‘is not’ is a single operator which
wheres pythonmonks wrote:
How does "x is not None" make any sense? "not x is None" does make sense.
I can only surmise that in this context (preceding is) "not" is not a
unary right-associative operator, therefore:
x is not None === IS_NOTEQ(X, None)
Beside "not in" which seems to work simila
On Aug 5, 2010, at 5:42 PM, wheres pythonmonks wrote:
How does "x is not None" make any sense? "not x is None" does make
sense.
I can only surmise that in this context (preceding is) "not" is not a
unary right-associative operator, therefore:
x is not None === IS_NOTEQ(X, None)
Beside "not
How does "x is not None" make any sense? "not x is None" does make sense.
I can only surmise that in this context (preceding is) "not" is not a
unary right-associative operator, therefore:
x is not None === IS_NOTEQ(X, None)
Beside "not in" which seems to work similarly, is there other
syntacti
55 matches
Mail list logo