Python method gets the path difference

Reference blog: https://blog.csdn.net/u011412768/article/details/84312226
conclude divided into three cases:

  • Get working directory path
    os.getcwd()
    is executed command-line directory, such as open cmd window, os.getcwd () to get the desktop of the desktop is a good path

  • Python get file path
    os.path.dirname(os.path.realpath(__file__))
    is the code in which file, the absolute path of the file is returned

  • Get the current file being executed python.exe path
    sys.path[0]
    such as test.py called test1.py, if python.exe execution test.py, then sys.path in test1.py the [0] to give the test.py path

Guess you like

Origin www.cnblogs.com/mrnx2004/p/11099254.html