Python IDLE或shell中切换路径

时间:2022-11-25 20:24:40
Python IDLE或shell中切换路径

在Python自带的编辑器IDLE中或者Python shell中不能使用cd命令,需要os模块的相关函数来操作。

具体如下:

import os  
os.getcwd() #获取当前路径  
os.chdir("D:\\test") #跳到目标路径下  
os.chdir('D:\\test') #单引号、双引号都可以