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

前端 未结 15 1139
傲寒
傲寒 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:33

    I have made a function to use when running python under IIS in CGI in order to get the current folder:

    import os 
       def getLocalFolder():
            path=str(os.path.dirname(os.path.abspath(__file__))).split('\\')
            return path[len(path)-1]
    

提交回复
热议问题