Python os.path.relpath behavior

后端 未结 3 475
小蘑菇
小蘑菇 2021-02-06 03:14

I have a directory bar inside a directory foo, with file foo_file.txt in directory foo and file bar_file.txt in

3条回答
  •  你的背包
    2021-02-06 03:39

    os.path.relpath() assumes that its arguments are directories.

    >>> os.path.join(os.path.relpath(os.path.dirname('foo/bar/bar_file.txt'),
            os.path.dirname('foo/foo_file.txt')),
            os.path.basename('foo/bar/bar_file.txt'))
    'bar/bar_file.txt'
    

提交回复
热议问题