I cannot evaluate this statement...

Michael Wieher michael.wieher at gmail.com
Fri Mar 7 16:38:14 EST 2008


The parentheses are there for a reason

2008/3/7, Steven D'Aprano <steve at remove-this-cybersource.com.au>:
>
> On Fri, 07 Mar 2008 12:38:11 -0800, waltbrad wrote:
>
> > The script comes from Mark Lutz's Programming Python.  It is the second
> > line of a script that will launch a python program on any platform.
> >
> > import os, sys
> > pyfile = (sys.platform[:3] == 'win' and 'python.exe') or 'python'
> >
> > Okay, run on a win32 machine, pyfile evaluates to python.exe
> >
> > That makes sense. Because the first condition is true and 'python.exe'
> > is true. So the next comparison is 'python.exe' or 'python'  Well,
> > python.exe is true. So that value is returned to pyfile.
> >
> > Now. Run this on linux. The first condition evaluates sys.platform[:3]
> > == 'win' as false. So, the next comparison should be  'False' or
> > 'python'   -- This is because 'and' returns the first false value. But,
> > again, on linux pyfile evaluates to python.exe
>
> Not on my Linux box.
>
>
> >>> import os, sys
> >>> sys.platform
> 'linux2'
> >>> (sys.platform[:3] == 'win' and 'python.exe') or 'python'
> 'python'
>
>
>
> > Where am I going wrong.  And when will this statment make pyfile
> > evaluate to 'python' ?
>
> When the first three letters of sys.platform aren't 'win'.
>
>
>
>
> --
> Steven
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080307/f6f6ef1c/attachment-0001.html>


More information about the Python-list mailing list