gpt4 book ai didi

python - 如何计算2个目录路径之间的相对路径?

转载 作者:太空狗 更新时间:2023-10-29 17:52:40 24 4
gpt4 key购买 nike

我有 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]) Return a relative filepath to path either from the current directory or from an optional start point.

start defaults to os.curdir.

Availability: Windows, Unix.

New in version 2.6.

关于python - 如何计算2个目录路径之间的相对路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7178001/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com