finding out absolute path to a file from python

后端 未结 5 484
孤城傲影
孤城傲影 2020-12-11 14:49

If I have a file test.py that resides in some directory, how can I find out from test.py what directory it is in? os.path.curdir will

5条回答
  •  遥遥无期
    2020-12-11 15:51

    Here's how to get the directory of the current file:

    import os
    os.path.abspath(os.path.dirname(__file__))
    

提交回复
热议问题