doing cross platform file work

John Gordon gordon at panix.com
Wed Jun 22 13:59:25 EDT 2011


In <mailman.292.1308764714.1164.python-list at python.org> Tim Hanson <tjhanson at yahoo.com> writes:

> For the more general case, I am a Linux user interested in making my scripts 
> platform neutral, which would include Linux, Unix (including Mac), and 
> Windows.  I have looked at the python.org os segment and didn't get an answer.

> Is there a library (bonus would be some tutorial material) for making sure my 
> Linux scripts access files and directories on the other platforms 
> transparently?  I don't need the information immediately, but at some point...

Your code should work on multiple platforms as long as you use standard
python functions like open(), print(), close(), etc.

Filesystem paths are a little trickier, as different platforms disallow
different characters in filenames, but as long as you stick to a common
set of characters that are legal in all cases you should be fine.  And of
course use os.sep.

Beyond that, what did you specifically have in mind?

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon at panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"




More information about the Python-list mailing list