os.chdir()

概述
  用于改变当前工作目录到指定的路径

语法
  os.chdir(path)

参数
  path 要切换到的新路径。

返回值
  True: 允许访问
  False: 不允许访问

使用示例

# -*- coding: UTF-8 -*-
import os, sys

retval = os.getcwd() #查看当前工作目录
print("当前工作目录为 %s" % retval) #输出:D:Temp

os.chdir(r"C:	mp") # 修改当前工作目录
retval = os.getcwd() # 获取修改后的工作目录
print("目录修改成功 %s" % retval) #输出:C:Temp
原文地址:https://www.cnblogs.com/shiliye/p/12120995.html