Multiplatform scripts: Can I avoid os.sep?

Bruno Desthuilliers onurb at xiludom.gro
Thu Jul 13 13:22:47 EDT 2006


gmax2006 wrote:
> Hi,
> 
> I am developing scripts that must run on both Linux and windows.
> 
> My scripts contain lots of relative paths (such as log\\log.txt or
> ctl\\table.ctl) If I use os.sep, it makes the code ugly. Is there any
> tips or techniques to have Python automatically converts \\ to / when
> the script runs on Linux? What is the best way to deal with this
> situation?

os.path.join('log', 'log.txt')
os.path.join('ctl', 'table.ctl')

Or look for the 'path' module
http://www.jorendorff.com/articles/python/path/

HTH
-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list