"Dan Stromberg" wrote:
You've got some good answers.
I've counted around 210 messages in this thread!!
I'd like to point out that this might make a good entry in a Python FAQ list...
Ok.
--
https://mail.python.org/mailman/listinfo/python-list
On Mon, Aug 18, 2014 at 1:35 PM, ElChino wrote:
> A newbie question to you; what is the difference between statements like:
> if x is not None:
> and
> if x != None:
>
> Without any context, which one should be preferred?
> IMHO, the latter is more readable.
You've got some good answers.
I'd li
Am 20.08.2014 13:17 schrieb Chris Angelico:
That's true, but how easy is it to annotate a file with each line's
author (or, at least, to figure out who wrote some particular line of
code)? It's easy enough with 'git blame' or 'hg blame', and it
wouldn't surprise me if bzr had a similar feature;
Rustom Mody :
> OP asks for 'is' (Haskell has no equivalent of 'is')
>
> Almost all the answers explain why its a bad idea
Well, I don't think it is a bad idea in and of itself, but if you don't
have it, you don't have to define it.
Object identity does make you look under the skin. In Python, i
On Wednesday, August 20, 2014 2:30:22 AM UTC+5:30, Marko Rauhamaa wrote:
> For a more worthy attempt, we'll have to take a look at Scheme ( http://www.scheme.com/tspl2d/objects.html>):
Since you brought up scheme, here is a discussion going on right now
on the Haskell list:
http://www.haskell.or
On Wednesday, August 20, 2014 4:35:42 PM UTC+5:30, Steven D'Aprano wrote:
> Rustom Mody wrote:
> > It is interesting (and insidious) how technology shapes our thinking
> > patterns. Before git,
> Pardon me, but git did not invent revision control. There are dozens of
> revision control software
On 2014-08-20 12:26, Tim Chase wrote:
On 2014-08-20 21:17, Chris Angelico wrote:
That's true, but how easy is it to annotate a file with each line's
author (or, at least, to figure out who wrote some particular line
of code)? It's easy enough with 'git blame' or 'hg blame', and it
wouldn't surpr
On Wed, Aug 20, 2014 at 9:26 PM, Tim Chase
wrote:
> On 2014-08-20 21:17, Chris Angelico wrote:
>> That's true, but how easy is it to annotate a file with each line's
>> author (or, at least, to figure out who wrote some particular line
>> of code)? It's easy enough with 'git blame' or 'hg blame',
On 2014-08-20 21:17, Chris Angelico wrote:
> That's true, but how easy is it to annotate a file with each line's
> author (or, at least, to figure out who wrote some particular line
> of code)? It's easy enough with 'git blame' or 'hg blame', and it
> wouldn't surprise me if bzr had a similar featu
On Wed, Aug 20, 2014 at 9:05 PM, Steven D'Aprano
wrote:
> Rustom Mody wrote:
>
>> It is interesting (and insidious) how technology shapes our thinking
>> patterns. Before git,
>
> Pardon me, but git did not invent revision control. There are dozens of
> revision control software applications, inc
Rustom Mody wrote:
> It is interesting (and insidious) how technology shapes our thinking
> patterns. Before git,
Pardon me, but git did not invent revision control. There are dozens of
revision control software applications, including:
Mercurial: released April 2005
Git: released April 2005
G
On Wednesday, August 20, 2014 10:29:13 AM UTC+5:30, Steven D'Aprano wrote:
> On Tue, 19 Aug 2014 21:01:49 -0700, Rustom Mody wrote:
> > I also (once!) had a student who started every single
> > variable/function/filename with his name!!
> I recall somebody on the Python tutor mailing list doing t
On Tue, 19 Aug 2014 21:01:49 -0700, Rustom Mody wrote:
> I also (once!) had a student who started every single
> variable/function/filename with his name!!
I recall somebody on the Python tutor mailing list doing that. They did
so because their course instructor made it a requirement and failed
On Wednesday, August 20, 2014 4:54:00 AM UTC+5:30, Ben Finney wrote:
> Tim Chase writes:
> > Am I the only one who feels the urge to write
> > if i am some_other_object: ...
> > if we are some_other_object: ...
> > if u are some_other_object: ... # though txtspk bothers me
> How often do yo
Tim Chase writes:
> Am I the only one who feels the urge to write
>
> if i am some_other_object: ...
> if we are some_other_object: ...
> if u are some_other_object: ... # though txtspk bothers me
How often do you need to refer to an object with personal pronouns? I
think for me the answer
Ian Kelly :
> On Tue, Aug 19, 2014 at 3:00 PM, Marko Rauhamaa wrote:
>> For a more worthy attempt, we'll have to take a look at Scheme (> http://www.scheme.com/tspl2d/objects.html>):
>
> Those are invariants, not a definition. The actual definition is
> found in the paragraph above:
>
> "In most
On 8/19/2014 3:05 PM, Mark Lawrence wrote:
On 19/08/2014 19:26, Steven D'Aprano wrote:
Marko Rauhamaa wrote:
CPython implementation detail: This is the address of the object
in memory.
I really wish CPython didn't do that, or at least not admit to it. It
does
nothing but conf
On Tue, Aug 19, 2014 at 3:00 PM, Marko Rauhamaa wrote:
> For a more worthy attempt, we'll have to take a look at Scheme ( http://www.scheme.com/tspl2d/objects.html>):
Those are invariants, not a definition. The actual definition is
found in the paragraph above:
"In most Scheme systems, two obje
Marko Rauhamaa :
> That's circular reasoning. When you are defining Python's execution
> model, you can't refer back to Python's execution model.
>
> For a good example of what I'm after, take a look how Java specifies its
> crucial happens-before relation:
>
>http://docs.oracle.com/javase
On 19/08/2014 19:26, Steven D'Aprano wrote:
Marko Rauhamaa wrote:
CPython implementation detail: This is the address of the object
in memory.
I really wish CPython didn't do that, or at least not admit to it. It does
nothing but confuse people.
I agree and would happily sup
Steven D'Aprano :
> Python identity is represented by an integer, and it is guaranteed to
> be unique and constant for the lifetime of the object. It may or may
> not be reused once the object no longer exists. That's all you need to
> know about identity; that's *all there is to know* about ident
On Tue, Aug 19, 2014 at 11:42 AM, Ian Kelly wrote:
> When I need to do this, I use:
>
> SENTINEL = object()
>
> It's still a singleton, and why should a sentinel be mutable?
Old habits die hard, I guess. I've been using Python since long before
object() existed. :-)
Skip
--
https://mail.pyt
Marko Rauhamaa wrote:
> Skip Montanaro :
>
>> The use of "is" or "is not" is the right thing to do when the object
>> of the comparison is known to be a singleton.
>
> Object identity stirs a lot of passions on this forum. I'm guessing the
> reason is that it is not defined very clearly ( https:
Tim Chase :
> Note that a lifetime can be less than a statement:
>
id([1,2,3]) == id([4,5,6])
> True
Duly noted.
Marko
--
https://mail.python.org/mailman/listinfo/python-list
Ian Kelly :
> When I need to do this, I use:
>
> SENTINEL = object()
>
> It's still a singleton, and why should a sentinel be mutable?
Private enums are often nicer in that they provide str() and repr().
Marko
--
https://mail.python.org/mailman/listinfo/python-list
On 2014-08-19 20:29, Marko Rauhamaa wrote:
> The "is" relation can be defined trivially through the id()
> function:
>
>X is Y iff id(X) == id(Y)
>
> What remains is the characterization of the (total) id() function.
> For example, we can stipulate that:
>
>X = Y
>assert(id(X) == id(
Skip Montanaro :
> The use of "is" or "is not" is the right thing to do when the object
> of the comparison is known to be a singleton.
Object identity stirs a lot of passions on this forum. I'm guessing the
reason is that it is not defined very clearly (https://docs.python.org/3/library/function
On Tue, Aug 19, 2014 at 7:12 AM, Skip Montanaro wrote:
> The use of "is" or "is not" is the right thing to do when the object
> of the comparison is known to be a singleton. That is true for None.
> (I suspect it's true for True and False as well, though for historical
> and idiomatic reasons "x i
On Tue, Aug 19, 2014 at 7:42 AM, Martin S wrote:
>> For example, in CPython 3.4.1:
> (254 + 3) is 257
>> False
> (254 + 3) == 257
>> True
> ('asd' + '@sd') is 'asd@sd'
>> False
> ('asd' + '@sd') == 'asd@sd'
>> True
>
> Now you have managed to confuse this newbie: What would a valid
2014-08-19 0:04 GMT+02:00 Chris Kaynor :
>
> On Mon, Aug 18, 2014 at 2:42 PM, Ethan Furman wrote:
>>
>> If you are not dealing with singletons (which is most cases), such as
>> numbers, strings, lists, and most other arbitrary objects, you will need to
>> use "!=" or anytime the two objects you ar
On 2014-08-19 08:36, Steven D'Aprano wrote:
> The English word "is" is the third-person singular simple present
> indicative form of "be",
Am I the only one who feels the urge to write
if i am some_other_object: ...
if we are some_other_object: ...
if u are some_other_object: ... # though
Am 18.08.2014 22:53 schrieb Marko Rauhamaa:
Frankly, I don't know of any other object that is "==" to the None
object except None itself, but such objects could possible exist.
class ImitatingNone(object):
def __eq__(self, other):
return True # is equal to everything else
r
Am 19.08.2014 00:04 schrieb Chris Kaynor:
In each of these cases, the behavior may be different in other
implementations or versions of Python.
And, the most important thing, in each of these cases, using "is" is
semantically wrong, so no matter how different versions behave.
If you ask the
On Mon, 18 Aug 2014 23:53:49 +0300, Marko Rauhamaa wrote:
> "ElChino" :
>
>> A newbie question to you; what is the difference between statements
>> like:
>> if x is not None:
>> and if x != None:
>
> Do the following: take two $10 bills. Hold one bill in the left hand,
> hold the other bill in
On Tue, Aug 19, 2014 at 6:36 PM, Steven D'Aprano wrote:
> Why do I know so much about the British royal family???
>
>
> [2] Of the UK, Australia, and a few other places, but not Denmark, or any
> other place with a Queen.
Possibly because British royalty is very well-defined, and can be used
to e
On Mon, 18 Aug 2014 19:29:11 -0700, Rustom Mody wrote:
> On Tuesday, August 19, 2014 2:05:01 AM UTC+5:30, ElChino wrote:
>> A newbie question to you; what is the difference between statements
>> like:
>> if x is not None:
>> and
>> if x != None:
>
>> Without any context, which one should be pr
On Tuesday, August 19, 2014 2:05:01 AM UTC+5:30, ElChino wrote:
> A newbie question to you; what is the difference between statements
> like:
> if x is not None:
> and
> if x != None:
> Without any context, which one should be preferred?
> IMHO, the latter is more readable.
Here is Terry Reed
On Mon, Aug 18, 2014 at 2:42 PM, Ethan Furman wrote:
> If you are not dealing with singletons (which is most cases), such as
> numbers, strings, lists, and most other arbitrary objects, you will need to
> use "!=" or anytime the two objects you are comparing are not the exact
> same object, you c
On 08/18/2014 03:04 PM, Chris Kaynor wrote:
On Mon, Aug 18, 2014 at 2:42 PM, Ethan Furman wrote:
If you are not dealing with singletons (which is most cases), such as numbers,
strings, lists, and most other
arbitrary objects, you will need to use "!=" or anytime the two objects you are
compar
On 08/18/2014 01:58 PM, ElChino wrote:
"Marko Rauhamaa" wrote:
In almost all cases, both tests would result in the same behavior.
However, the "is not" test is conceptually the correct one since you
want to know if x is the one and only None object. You don't want to be
fooled by an imposter o
"Marko Rauhamaa" wrote:
In almost all cases, both tests would result in the same behavior.
However, the "is not" test is conceptually the correct one since you
want to know if x is the one and only None object. You don't want to be
fooled by an imposter object that simply looks like the None ob
"ElChino" :
> A newbie question to you; what is the difference between statements
> like:
> if x is not None:
> and
> if x != None:
Do the following: take two $10 bills. Hold one bill in the left hand,
hold the other bill in the right hand.
Now, the bill in the left hand "is not" the bill in th
On 2014-08-18 21:35, ElChino wrote:
A newbie question to you; what is the difference between statements
like:
if x is not None:
and
if x != None:
Without any context, which one should be preferred?
IMHO, the latter is more readable.
"x == y" tells you whether x and y refer to objects that
A newbie question to you; what is the difference between statements
like:
if x is not None:
and
if x != None:
Without any context, which one should be preferred?
IMHO, the latter is more readable.
--
https://mail.python.org/mailman/listinfo/python-list
44 matches
Mail list logo