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