def replace_prefix(path, p1, p2):
 common_prefix = os.path.commonprefix([path, p1])
 if common_prefix:
  assert (path.find(common_prefix) == 0)
  path = path[(len(common_prefix) + 1):]
 return os.path.join(p2, path)

def replace_prefix ( path , p1 , p2 ) : common_prefix = os . path . commonprefix ( [ path , p1 ] ) if common_prefix : assert ( path . find ( common_prefix ) == 0 ) path = path [ ( len ( common_prefix ) + 1 ) : ] return os . path . join ( p2 , path )
replace p1 in path with p2 .