Python学习笔记(14) -- Python IDLE或shell中切换路径

来源:互联网 发布:mysql keepalived 编辑:程序博客网 时间:2024/05/29 08:36

原文链接:http://blog.csdn.net/garfielder007/article/details/50808015


在Python自带的编辑器IDLE中或者Python shell中不能使用cd命令,那么跳到目标路径呢。


方法是使用os包下的相关函数实现路径切换功能。

[python] view plain copy
  1. import os  
  2. os.getcwd() #获取当前路径  
  3. os.chdir("D:\\test"#跳到目标路径下  
  4. os.chdir('D:\\test'#单引号、双引号都可以