def relative_path(filename, start=os.path.curdir):
 try:
  (dirname, basename) = os.path.split(filename)
  relative_dir = os.path.relpath(dirname, start)
  return os.path.join(relative_dir, basename)
 except ValueError:
  return os.path.abspath(filename)

def relative_path ( filename , start = os . path . curdir ) : try : ( dirname , basename ) = os . path . split ( filename ) relative_dir = os . path . relpath ( dirname , start ) return os . path . join ( relative_dir , basename ) except ValueError : return os . path . abspath ( filename )
cross platform relative path of a filename .