473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

rules of thumb for cross os code

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 ?
Aug 22 '08 #1
3 826
On Aug 22, 9:55*am, DwBear75 <dwbea...@gmail.comwrote:
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.
Aug 22 '08 #2
In article <76**********************************@v16g2000prc. googlegroups.com>,
DwBear75 <dw******@gmail.comwrote:
>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
Aug 23 '08 #3
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.
</obvious>
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'"


Aug 26 '08 #4

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

Similar topics

4
by: AES/newspost | last post by:
Can anyone provide a quick tip on the html structure to link from a thumb to a movie poster and from there on to a QuickTime movie, all in one go, using EMBED? I have a number of (large)...
1
by: BillyTheKid | last post by:
Are there any rules of thumb for when it is more appropriate to use WinForms over WebForms. It strikes me that WinForms is best suited for many/most "Intranet" and some "Extranet" scenarios but...
7
by: Jack | last post by:
Are there any rules of thumb for when it is appropriate to use grid mode vs. flow mode in the Visual Studio.NET WebForm designer?
3
by: n2xssvv g02gfr12930 | last post by:
Although I rarely if ever have a problem with scope, I was wondering whether anybody knows of good reference, (book, web page, etc), that covers scope rules. Hopefully this will be helpful to...
6
by: moondaddy | last post by:
I'm writing a windows app in WPF and want to change the shape of a thumb to an ellipse. Is this possible? also, the edges of the thumb are beveled. Is it possible to change this to a flat look...
2
by: moondaddy | last post by:
I'm trying to do something real simple. Add a thumb to a grid at the end of a line using c#. the code executes but I dont see the thumb. Can anyone explain what and what I need to do to properly...
3
by: PW | last post by:
Hi, I just bought a SanDisk Cruzer 4GB "U3" thumb drive. Is it possible to run an Access 2003 MDE off of one, complete with data? If so, what would I have to do to get it to work? Just...
3
by: moondaddy | last post by:
I have a wpf app and need to apply a control template to a thumb at runtime, but I can't do it the same way I would apply a style. this is what I want to do: Thumb thm = new Thumb();...
1
by: Linda Liu[MSFT] | last post by:
Hi George, Thank you for posting! This is a quick note to let you know that I am doing research on this issue and will get back to you ASAP. I appreciate your patience! Sincerely,
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.