Sign in to follow this  
wood_brian

python test prog

Recommended Posts

wood_brian    193
I want to use a python program on different platforms. And it has to do something different on different platforms. For example, on Linux it needs to remove atest.o and on Windows atest.obj. How to tell which platform I'm on? Does the user have to call it differently? Tia

Share this post


Link to post
Share on other sites
SiCrane    11839
Depending on what kind of granularity of information you want you can look at the os and platform modules. In particular you might want to try os.name or platform.system.

Share this post


Link to post
Share on other sites
wood_brian    193
I have a problem using sys.platform or platform.system on Windows 7.

This is what I have:
import os
import sys

print sys.platform

os.system("touch bigtest.generated.o")
os.remove("bigtest.generated.o")

--------------------------------------------------------------------------------
on Linux the output is linux2.

On Windows I get

print sys.platform
^
SyntaxError: invalid syntax

I'm running it under cygwin and a bash shell on Windows. If I comment out the print line, the os.system and os.remove lines work fine. I've have this in my environment -- PYTHONPATH='C:\Python32\Lib;C:\Python32\DLLs' . Any idea what is wrong?

I get the same result when I run it under cmd.exe.


Figured it out. In Python 3 you have to use print as a function. So print(sys.platform) works. It would be nice if Python gave a more informative error message.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this