首页 > 代码库 > Python IDLE或shell中切换路径

Python IDLE或shell中切换路径

在Python自带的编辑器IDLE中或者python shell中不能使用cd命令,那么跳到目标路径呢。方法是使用os包下的相关函数实现路径切换功能。

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

Python IDLE或shell中切换路径