Jeffrey Barish wrote:

I have a small program that I would like to run on multiple platforms
(at least linux and windows).  My program calls helper programs that
are different depending on the platform.  I think I figured out a way
to structure my program, but I'm wondering whether my solution is good
Python programming practice.


I use something like this in the setup code:

if os.name == 'posix':
  statfunction = os.lstat
else:
  statfunction = os.stat

and then further in the code:

x = statfunction(filename)

So the idea is to have your "own" function names and assign the os-specific functions one and for all in the beginning. Afterwards, your code only uses your own function names and, as long as they behave in the same way, there's no more if - else stuff.

-pu
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to