On Thu, 2009-10-08 at 12:58 -0700, wesley chun wrote:
> wow, as the OP, you must have been surprised to see how far we have
> taken your (seemingly) simple question.
Pleasently suprised :-) And I am gratefull to see the heavy weights join
in.
> however, what i did *not* mention is that these (abb
> Thanks all for the informative discussion. To re-confirm it was mostly
> for boolean checks like "if b == True".
wow, as the OP, you must have been surprised to see how far we have
taken your (seemingly) simple question. we went from boolean checks to
interning! commenting on my previous reply,
On Mon, Oct 5, 2009 at 9:13 PM, Luke Paireepinart
wrote:
> Actually, I just realized that "not" has higher precedence than "==" so this
> is really checking if (not n) is equal to 0, not if (n == 0) is (not) True.
No, "not" is lower precedence than "==". See
http://docs.python.org/reference/expr
On Tue, Oct 6, 2009 at 2:40 AM, Vern Ceder wrote:
> Dave Angel wrote:
>
> Now in this case where it is only used as boolean checks which would be
the most pythonic way if writing these checks?
>>> The shorter version may be preferable, but it doesn't generally give the
>> same res
On Tue, Oct 6, 2009 at 9:04 AM, Wayne wrote:
> If it's checking the returncode against a value, Vern makes a good point:
> if returncode != 0 makes a whole lot more sense than "if not returncode ==
> 0"
> Though when dealing with an integer return code, doesn't it make more sense
> to use the "is
On Tue, Oct 6, 2009 at 11:08 AM, Wayne wrote:
> On Tue, Oct 6, 2009 at 9:58 AM, Dave Angel wrote:
>>
>>
>>
>> No, because you're not assured that all integers that are equal are the
>> same object. Python optimizes that for small integers, but there's no
>> documented range that you can count o
Thanks all for the informative discussion. To re-confirm it was mostly
for boolean checks like "if b == True".
Greets
Sander
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/t
On Tue, Oct 6, 2009 at 5:08 PM, Wayne wrote:
> On Tue, Oct 6, 2009 at 9:58 AM, Dave Angel wrote:
>>
>>
>>
>> No, because you're not assured that all integers that are equal are the
>> same object. Python optimizes that for small integers, but there's no
>> documented range that you can count on
On Tue, Oct 6, 2009 at 9:58 AM, Dave Angel wrote:
>
No, because you're not assured that all integers that are equal are the same
> object. Python optimizes that for small integers, but there's no documented
> range that you can count on it.
>
>
But for this specific case - checking a return co
Wayne wrote:
On Mon, Oct 5, 2009 at 3:37 PM, Sander Sweers wrote:
Thanks Wesly/Vern for the replies.
On Mon, 2009-10-05 at 21:56 +0200, Luke Paireepinart wrote:
if not n == 0
if b == True can be written as if b.
However,
if not n == 0 can be written as if n != 0 but NOT as
On Mon, Oct 5, 2009 at 3:37 PM, Sander Sweers wrote:
> Thanks Wesly/Vern for the replies.
>
> On Mon, 2009-10-05 at 21:56 +0200, Luke Paireepinart wrote:
> > if not n == 0
> >
> > if b == True can be written as if b.
> >
> >
> > However,
> > if not n == 0 can be written as if n != 0 but NO
On Mon, Oct 5, 2009 at 9:28 PM, Sander Sweers wrote:
>
> Hi Tutors,
>
> I am going through someone's python script and I am seeing a lot of the
> following boolean checks.
>
> if not s == ""
>
> if not n == 0
>
> if b == True
>
> if not b == True
>
> etc..
>
> All of these can be written without t
Dave Angel wrote:
Now in this case where it is only used as boolean checks which would be
the most pythonic way if writing these checks?
The shorter version may be preferable, but it doesn't generally give the
same results. Without knowing the possible data, these substitutions
are not saf
Vern Ceder wrote:
Hi Sander,
PEP 8, the "Style Guide for Python Code"
http://www.python.org/dev/peps/pep-0008/ is pretty clear that the
shorter version is preferable:
if s:
if n:
if b:
if not b:
and so on...
Cheers,
Vern
Sander Sweers wrote:
Hi Tutors,
I am going through someone's pytho
> I am going through someone's python script and I am seeing a lot of the
> following boolean checks.
>
> if not s == ""
> if not n == 0
> if b == True
> if not b == True
> etc..
>
> All of these can be written without the == notation like "if n", "if s"
> etc.Now in this case where it is only used
Thanks Wesly/Vern for the replies.
On Mon, 2009-10-05 at 21:56 +0200, Luke Paireepinart wrote:
> if not n == 0
>
> if b == True can be written as if b.
>
>
> However,
> if not n == 0 can be written as if n != 0 but NOT as if n.
> The reason why is that 0 is not equivalent to False even
Hi Sander,
PEP 8, the "Style Guide for Python Code"
http://www.python.org/dev/peps/pep-0008/ is pretty clear that the
shorter version is preferable:
if s:
if n:
if b:
if not b:
and so on...
Cheers,
Vern
Sander Sweers wrote:
Hi Tutors,
I am going through someone's python script and I am s
Hi Tutors,
I am going through someone's python script and I am seeing a lot of the
following boolean checks.
if not s == ""
if not n == 0
if b == True
if not b == True
etc..
All of these can be written without the == notation like "if n", "if s"
etc.
Now in this case where it is only used
18 matches
Mail list logo