__python中操作路径,最好用绝对路径。__这样会避免在多个脚本调用过程中或不同层级调用过程中出现混乱
os.getcwd()
sys.argv[0]
sys.path[0]
__file__
python os模块中的 os.path.realpath()函数接收一个模块,返回绝对路径
os.path.realpath()
配合__file__一起使用: os.path.realpath(__file__) 这样可以返回一个文件的绝对路径,且不会出现由于在别的目录中,调用该脚本而出现路径混乱的现象。
os.path.realpath(__file__)