Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?

2008-01-23 Thread Kristian Domke
Hello to all I am trying to learn python at the moment studying an example program (cftp.py from the twisted framework, if you want to know) There I found a line foo = (not f and 1) or 0 In this case f may be None or a string. If I am not wrong here, one could simply write foo = not f

Re: Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?

2008-01-23 Thread cokofreedom
On Jan 23, 9:45 am, Kristian Domke [EMAIL PROTECTED] wrote: Hello to all I am trying to learn python at the moment studying an example program (cftp.py from the twisted framework, if you want to know) There I found a line foo = (not f and 1) or 0 In this case f may be None or a string.

Re: Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?

2008-01-23 Thread Gary Herron
Kristian Domke wrote: Hello to all I am trying to learn python at the moment studying an example program (cftp.py from the twisted framework, if you want to know) There I found a line foo = (not f and 1) or 0 In this case f may be None or a string. If I am not wrong here, one could

Re: Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?

2008-01-23 Thread Jarek Zgoda
Gary Herron napisaƂ(a): However there *is* a (subtle) difference between not f and (not f and 1) or 0 The first produces a boolean value, and the second produces an int value, but since one is a subclass of the other, you'd have to write quite perverse code care about the

Re: Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?

2008-01-23 Thread cokofreedom
Sorry, posted to quickly. Yes your logic is correct about the logic of the return, but theirs actually differs in what it returns, and I am guessing it is an important change. Where is this foo used? Perhaps its value is used in a way a boolean return couldn't be? Just a note, with these kind of

Re: Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?

2008-01-23 Thread Duncan Booth
Kristian Domke [EMAIL PROTECTED] wrote: foo = (not f and 1) or 0 In this case f may be None or a string. If I am not wrong here, one could simply write foo = not f Yes, it sounds pretty silly, and not just on the level you spotted. The only difference between the two expressions is

Re: Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?

2008-01-23 Thread Boris Borcic
I am surprised nobody pointed out explicitely that True==1 and False==0 so that for instance 5*(True+True)==10 and even (but implementation-dependent) : 5*(True+True) is 10 BB -- http://mail.python.org/mailman/listinfo/python-list

Re: Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?

2008-01-23 Thread Steven D'Aprano
On Wed, 23 Jan 2008 09:30:28 +, Duncan Booth wrote: Kristian Domke [EMAIL PROTECTED] wrote: foo = (not f and 1) or 0 In this case f may be None or a string. If I am not wrong here, one could simply write foo = not f Yes, it sounds pretty silly, and not just on the level you

Re: Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?

2008-01-23 Thread Gary Herron
Boris Borcic wrote: I am surprised nobody pointed out explicitely that True==1 and False==0 Several of us did indeed point this out by saying that bool's are a subclass of ints. so that for instance 5*(True+True)==10 and even (but implementation-dependent) : 5*(True+True) is 10 BB

Re: Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?

2008-01-23 Thread Duncan Booth
Steven D'Aprano [EMAIL PROTECTED] wrote: On Wed, 23 Jan 2008 09:30:28 +, Duncan Booth wrote: Kristian Domke [EMAIL PROTECTED] wrote: foo = (not f and 1) or 0 In this case f may be None or a string. If I am not wrong here, one could simply write foo = not f Yes, it sounds

Re: Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?

2008-01-23 Thread Steven Bethard
Kristian Domke wrote: I am trying to learn python at the moment studying an example program (cftp.py from the twisted framework, if you want to know) There I found a line foo = (not f and 1) or 0 Equivalent to ``foo = int(not f)`` In this case f may be None or a string. If I am not

Re: Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?

2008-01-23 Thread George Sakkis
On Jan 23, 4:06 am, Gary Herron [EMAIL PROTECTED] wrote: However there *is* a (subtle) difference between not f and (not f and 1) or 0 The first produces a boolean value, and the second produces an int value, but since one is a subclass of the other, you'd have to write quite perverse