How do I get the full path of the current file's directory?

前端 未结 15 1151
傲寒
傲寒 2020-11-22 17:01

I want to get the current file\'s directory path. I tried:

>>> os.path.abspath(__file__)
\'C:\\\\python27\\\\test.py\'

But how can

15条回答
  •  生来不讨喜
    2020-11-22 17:36

    System: MacOS

    Version: Python 3.6 w/ Anaconda

    import os
    
    rootpath = os.getcwd()
    
    os.chdir(rootpath)
    

提交回复
热议问题