os.path.split gets confused with combined \\ and /

Stef Mientki stef.mientki at gmail.com
Sun May 17 06:11:20 EDT 2009


hello,

just wonder how others solve this problem:
I've to distribute both python files and data files.
Everything is developed under windows and now the datafiles contains 
paths with mixed \\ and /.
Under windows everthing is working well,
but under Ubuntu / Fedora sometimes strange errors occurs.
Now I was thinking that using os.path.split would solve all problems,
but if I've the following relative path

    path1/path2\\filename.dat

split will deliver the following under windows
   path = path1 / path2
   filename = filename.dat

while under Linux it will give me
   path = path1
   filename = path\\filename.dat

So I'm now planning to replace all occurences of os.path.split with a 
call to the following function

def path_split ( filename ) :
    # under Ubuntu a filename with both
    # forward and backward slashes seems to give trouble
    # already in os.path.split
    filename = filename.replace ( '\\','/')

    return os.path.split ( filename )

how do others solve this problem ?
Are there better ways to solve this problem ?

thanks,
Stef Mientki



More information about the Python-list mailing list