我有2个目录:
subdir1 = live/events/livepkgr/events/_definst_/
subdir2 = live/streams/livepkgr/streams/_definst_/
结果必须是:
diff_subdir = ../../../../streams/livepkgr/streams/_definst_/
我有2个目录:
subdir1 = live/events/livepkgr/events/_definst_/
subdir2 = live/streams/livepkgr/streams/_definst_/
结果必须是:
diff_subdir = ../../../../streams/livepkgr/streams/_definst_/
http://docs.python.org/library/os.path.html
os.path.relpath(path[, start]) 函数返回从当前目录或可选起始点到路径 path 的相对文件路径。>>> subdir1 = "live/events/livepkgr/events/_definst_/"
>>> subdir2 = "live/streams/livepkgr/streams/_definst_/"
>>> import os
>>> os.path.relpath(subdir2, subdir1)
'../../../../streams/livepkgr/streams/_definst_'
>>>