我有2个目录:
subdir1 = live/events/livepkgr/events/_definst_/
subdir2 = live/streams/livepkgr/streams/_definst_/
Run Code Online (Sandbox Code Playgroud)
结果必须是:
diff_subdir = ../../../../streams/livepkgr/streams/_definst_/
Run Code Online (Sandbox Code Playgroud)
小智 20
http://docs.python.org/library/os.path.html
os.path.relpath(path [,start])将相对文件路径从当前目录或可选起始点返回到路径.
启动默认为os.curdir.
可用性:Windows,Unix.
2.6版中的新功能.
Dog*_*ert 17
>>> subdir1 = "live/events/livepkgr/events/_definst_/"
>>> subdir2 = "live/streams/livepkgr/streams/_definst_/"
>>> import os
>>> os.path.relpath(subdir2, subdir1)
'../../../../streams/livepkgr/streams/_definst_'
>>>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5225 次 |
| 最近记录: |