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 pathPython get file path
os.path.dirname(os.path.realpath(__file__))
is the code in which file, the absolute path of the file is returnedGet 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