rules of thumb for cross os code

D

DwBear75

I am considering using python as a replacement for a lot of bash
scripting that I have been doing. I would like to be as cross platform
as possible, writing scripts for both windows and linux. Are there any
guides are general rules of thumb on
1) keeping code os independant
2) nifty lambda's or other things to create functions fit for the
environment
3) capturing return codes of other executables called from python; ie
use os.system, or popen? or ?
 
A

Adam E

I am considering using python as a replacement for a lot of bash
scripting that I have been doing. I would like to be as cross platform
as possible, writing scripts for both windows and linux. Are there any
guides are general rules of thumb on
1) keeping code os independant
2) nifty lambda's or other things to create functions fit for the
environment
3) capturing return codes of other executables called from python; ie
use os.system, or popen? or ?

you can try Programming Python 3rd Edition from O'Reilly or, at least,
the code for the book, which you can get from the author's site:
http://www.rmi.net/~lutz/
Note: it contains code for Python 2.4, but I never encountered any of
the code to not work when I tried it. There is one directory that
contains out-of-date code, which you should find easily when reading
the text files.


I'm sorry that I can only help by referring you to Python 2.4 code.
But it is useful -- PyMailGUI and PyMailCGI are great examples, just
be careful not to be fed up with the large, high-level examples.
 
B

Bruno Desthuilliers

DwBear75 a écrit :
I am considering using python as a replacement for a lot of bash
scripting that I have been doing. I would like to be as cross platform
as possible, writing scripts for both windows and linux. Are there any
guides are general rules of thumb on
1) keeping code os independant

<obvious>
Use os.path, avoid any os-specific module.
2) nifty lambda's or other things to create functions fit for the
environment

You don't need lambdas here.

import random
some_condition = random.choice((True, False))

if some_condition:
def myfunc():
print "myfunc for 'somecondition==True'"
else:
def myfunc():
print "myfunc for 'somecondition==False'"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top