473,473 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

I cannot evaluate this statement...

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

Where am I going wrong. And when will this statment make pyfile
evaluate to 'python' ?
Mar 7 '08 #1
2 1237
On Fri, Mar 7, 2008 at 3:38 PM, waltbrad <wa******@hotmail.comwrote:
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
This seems to work as expected on my Ubuntu box.

Python 2.5.1 (r251:54863, Oct 5 2007, 13:36:32)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>import os, sys
sys.platform
'linux2'
>>pyfile = (sys.platform[:3] == 'win' and 'python.exe') or 'python'
pyfile
'python'
>>>
What do you get for sys.platform when you run this code under linux?

--
Jerry
Mar 7 '08 #2
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
Mar 7 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Steve | last post by:
Hello, I've been a PHP programmer for a number of years and have just started to learn JS. My Employer (a water analysis lab) wants what should be a very simple .js written that basically takes...
1
by: A E | last post by:
Hi, Was wondering if there was anything akin to an evaluate statement in Postgresql for dynamic strings? Alex
3
by: Jason luo | last post by:
Hi all, In c99-standard page 52,there is a sentence about void,as below: If an expression of any other type is evaluated as a void expression, its value or designator is discarded. I don't...
22
by: Paminu | last post by:
As I remember if(1) evaluates to true and all other numbers including 0 evaluate to false. But where do I find out about this for sure?? I have looked through K&R, all the C for dummies books...
2
by: Rick427 | last post by:
I am new to .NET and was wondering if there is a function like the evaluate function in Cold Fusion that lets you use the value of something as a variable name instead of using a select case...
8
by: No Such Luck | last post by:
Is there anyway to literally evaluate the contents of a string in an if statement? For example: int i = 0; char * str = "i == 0"; if(str) /* I know this doesn't do what I want */ {
3
by: Adam J Knight | last post by:
Hi all, I am getting the following error with this if statement.. if(e.Item.DataItem != 2) { } //error Cannot apply indexing with to an expression of type 'object' Can someone fill me in on...
2
by: steevehetu18 | last post by:
Hi, I'm doing a algorithm to calcule Earliest Start et Latest Start for a Graph with Nodes and Arcs. (like a PERT diagram) . Unfortunatly, i receive a wierd exception message for a specific...
4
by: Massimo | last post by:
I have a very very strange situation with a particular application and sql server 2005 enterprise. This application combines numerical data from multiple tables. User can make query over this...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.