小白教程
所有教程
关于
Search
172.69.59.136
172.69.59.136
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python3 os chdir”的源代码
本页内容
上一节:
Python3_os_access
下一节:
Python3_os_chflags
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:os.chdir(path)}}[[Category:python3 os file methods|2]] = Python3 os.chdir() 方法 = [[python3 os file methods|Python3 OS 文件/目录方法]] === 概述 === os.chdir() 方法用于改变当前工作目录到指定的路径。 === 语法 === '''chdir()'''方法语法格式如下: <sample title="" desc="" lang="python" hererun="1"> os.chdir(path) </sample> === 参数 === * '''path''' -- 要切换到的新路径。 === 返回值 === 如果允许访问返回 True , 否则返回False。 == 以下实例演示了 chdir() 方法的使用: <sample title="" desc="" lang="python" hererun="1"> #!/usr/bin/python3 import os, sys path = "/tmp" # 查看当前工作目录 retval = os.getcwd() print ("当前工作目录为 %s" % retval) # 修改当前工作目录 os.chdir( path ) # 查看修改后的工作目录 retval = os.getcwd() print ("目录修改成功 %s" % retval) </sample> 执行以上程序输出结果为: <sample title="" desc="" lang="python" hererun="1"> 当前工作目录为 /www 目录修改成功 /tmp </sample> [[python3 os file methods|Python3 OS 文件/目录方法]]
返回至“
Python3 os chdir
”。
上一节:
Python3_os_access
下一节:
Python3_os_chflags