Python方法chdir()将当前工作目录更改为给定的路径。在所有情况下都不返回。
os.chdir(path)
path - 这是要更改到新位置的目录的完整路径。
以下示例显示了chdir()方法的用法。
#!/usr/bin/python import os path="/usr/tmp" # Check current working directory. retval=os.getcwd() print "Current working directory %s" % retval # Now change the directory os.chdir( path ) # Check current working directory. retval=os.getcwd() print "Directory changed successfully %s" % retval
当无涯教程运行上面的程序时,它产生以下输出-
链接:https://www.learnfk.comhttps://www.learnfk.com/python/os-chdir.html
来源:LearnFk无涯教程网
Current working directory /usr Directory changed successfully /usr/tmp
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)