How to resolve relative paths in python?

后端 未结 4 1017
遇见更好的自我
遇见更好的自我 2021-02-18 12:57

I have Directory structure like this

projectfolder/fold1/fold2/fold3/script.py

now I\'m giving script.py a path as commandline argument of a fi

4条回答
  •  忘掉有多难
    2021-02-18 13:30

    For Python3, you can use pathlib's resolve functionality to resolve symlinks and .. components.

    You need to have a Path object however it is very simple to do convert between str and Path.

    I recommend for anyone using Python3 to drop os.path and its messy long function names and stick to pathlib Path objects.

提交回复
热议问题