绝对路径
1、os.path 方法
import os
import sys
current_directory = os.path.dirname(os.path.abspath(__file__))
print(current_directory)


2、os.path.abspath 方法
import os
import sys
root_path = os.path.abspath(os.path.dirname(current_directory) + os.path.sep + ".")
sys.path.append(root_path)
print(sys.path[0])
 

3、os.getcwd 方法
currentPath = os.getcwd().replace('\\','/')    # 获取当前路径
print(currentPath)
 

1 import os
2 print(os.getcwd())  #获取当前工作目录路径
3 print(os.path.abspath(‘.’))    #获取当前工作目录路径

 

要设置的当前目录
os.chdir('d:\\aa')