小白教程
所有教程
关于
Search
172.70.126.103
172.70.126.103
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python3 os getcwd”的源代码
本页内容
上一节:
Python3_os_ftruncate
下一节:
Python3_os_getcwdb
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:os.getcwd()}}[[Category:python3 os file methods|21]] = Python3 os.getcwd() 方法 = [[python3 os file methods|Python3 OS 文件/目录方法]] === 概述 === os.getcwd() 方法用于返回当前工作目录。 === 语法 === '''getcwd()'''方法语法格式如下: <sample title="" desc="" lang="python" hererun="1"> os.getcwd() </sample> === 参数 === * 无 === 返回值 === 返回当前进程的工作目录。 == 以下实例演示了 getcwd() 方法的使用: <sample title="" desc="" lang="python" hererun="1"> #!/usr/bin/python3 import os, sys # 切换到 "/var/www/html" 目录 os.chdir("/var/www/html" ) # 打印当前目录 print ("当前工作目录 : %s" % os.getcwd()) # 打开 "/tmp" fd = os.open( "/tmp", os.O_RDONLY ) # 使用 os.fchdir() 方法修改目录 os.fchdir(fd) # 打印当前目录 print ("当前工作目录 : %s" % os.getcwd()) # 关闭文件 os.close( fd ) </sample> 执行以上程序输出结果为: <sample title="" desc="" lang="python" hererun="1"> 当前工作目录 : /var/www/html 当前工作目录 : /tmp </sample> [[python3 os file methods|Python3 OS 文件/目录方法]]
返回至“
Python3 os getcwd
”。
上一节:
Python3_os_ftruncate
下一节:
Python3_os_getcwdb