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

前端 未结 15 1087
傲寒
傲寒 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条回答
  •  -上瘾入骨i
    2020-11-22 17:38

    If you just want to see the current working directory

    import os
    print(os.getcwd)
    

    If you want to change the current working directory

    os.chdir(path)
    

    path is a string containing the required path to be moved. e.g.

    path = "C:\\Users\\xyz\\Desktop\\move here"
    

提交回复
热议问题