windows / unix path

John Machin sjmachin at lexicon.net
Sat Oct 18 16:45:12 EDT 2008


On Oct 19, 6:00 am, Marcin201 <marcin... at gmail.com> wrote:
> Is there an built-in functionality in python to convert Windows paths
> to Unix paths?  I am running into problems when creating data files on
> Windows and the running them on a Unix platform.  I create paths using
> os.path.join.
>
> os.path.join('Pictures', '01.jpg') returns 'Pictures\\01..jpg' on
> Win.  When I read files created on Win under Unix this is a problem,
> python cannot open 'Pictures\\01.jpg'
>

Note that os.path.join('Pictures', '01.jpg') returns 'Pictures/01.jpg'
on Unix.
Note that 'Pictures\\01.jpg' == r'Pictures\01.jpg' i.e. there is only
one backslash.
Have you considered unix_path = windows_path.replace('\\', '/')?




More information about the Python-list mailing list