OS File 中的 os.chdir(path)函数

首页 / Python2入门教程 / OS File 中的 os.chdir(path)函数

Python方法chdir()将当前工作目录更改为给定的路径。在所有情况下都不返回。

os.chdir(path) - 语法

os.chdir(path)
  • path  -  这是要更改到新位置的目录的完整路径。

os.chdir(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

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

硅谷产品实战36讲 -〔曲晓音〕

Python核心技术与实战 -〔景霄〕

Vim 实用技巧必知必会 -〔吴咏炜〕

Go 并发编程实战课 -〔晁岳攀(鸟窝)〕

技术面试官识人手册 -〔熊燚(四火)〕

攻克视频技术 -〔李江〕

超级访谈:对话毕玄 -〔毕玄〕

现代C++20实战高手课 -〔卢誉声〕

结构思考力 · 透过结构看表达 -〔李忠秋〕

好记忆不如烂笔头。留下您的足迹吧 :)