Re: File Handling Problems Python I/O

2005-01-06 Thread mhartl
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')
'/foo/bar/baz'

On a Windows machine, you get

>>> BASE = 'C:'
>>> import os
>>> os.path.join(BASE, 'foo', 'bar', 'baz')
'C:\\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 http://docs.python.org/lib/module-os.path.html for more
information.
Cheers,

Michael

--
Michael Hartl
http://michaelhartl.org/

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


Re: File Handling Problems Python I/O

2005-01-06 Thread mhartl
Sorry, the BASE variable should be 'C:\\' on Windows:

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

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