Python os.path.relpath behavior

后端 未结 3 505
小蘑菇
小蘑菇 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:36

    os.path.relpath(arg1, arg2) 
    

    will give the relative path of arg2 from the directory of arg1. In order to get from arg2 to arg1 in your case, you would need to cd up one directory(..), go the bar directory(bar), and then the bar_file.txt. Therefore, the relative path is

    ../bar/bar_file.txt
    

提交回复
热议问题