File Handling Problems Python I/O

mhartl at mhartl at
Thu Jan 6 15:34:52 EST 2005

You can use the os module to build path names in a platform-independent
manner.  On my Linux box, I can type

>>> BASE = '/'
>>> import os
>>> os.path.join(BASE, 'foo', 'bar', 'baz')

On a Windows machine, you get

>>> BASE = 'C:'
>>> import os
>>> os.path.join(BASE, 'foo', 'bar', 'baz')

This is a little more cumbersome that just typing the string, but using
os.path.join makes it easy to port your scripts to a new platform.
Check out for more


Michael Hartl

More information about the Python-list mailing list