file delimiter in dependency of os

Peter Hansen peter at engcorp.com
Sun Nov 2 14:39:18 CET 2003


Peter Otten wrote:
> 
> Thomas Steffen wrote:
> 
> > Hallo,
> >
> > I have pathes with different file delimiters
> > e.g.
> > /root/dir\mydir/myfile
> > C:\xxx/hh\gggg/myfile
> >
> > How can I change the mistaken file delimiters in dependency of the
> > used os (win or unix) effectively?
> > unix: /root/dir\mydir --> /root/dir/mydir
> > win: C:\xxx/hh\gggg/myfile --> C:\xxx\hh\gggg\myfile
> >
> > Thanks for your hints Thomas
> 
> Note that backslashes are only needed for the conventional user experience,
> Windows is happy with "/", too. Have a look at os.path.normcase() which

Or, to be more practical, backslashes are needed for commands that are
passed to the MS-DOS shell with os.system() and friends.  Any other
way of getting the paths to the OS should work with forward slashes.

-Peter




More information about the Python-list mailing list