finding out absolute path to a file from python

后端 未结 5 468
孤城傲影
孤城傲影 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:35

    the answer is to use:

     __file__
    

    which returns a relative path.

    os.path.abspath(__file__) 
    

    can be used to get the full path.

提交回复
热议问题