小白教程
所有教程
关于
Search
172.70.178.164
172.70.178.164
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python3 os pardir”的源代码
本页内容
上一节:
Os_write
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:os.pardir()}}[[Category:python3 os file methods|64]] = Python3 os.pardir 方法 = [[python3 os file methods|Python3 OS 文件/目录方法]] === 概述 === os.pardir() 获取当前目录的父目录(上一级目录),以字符串形式显示目录名。 '''注意:''' Windows 和 POSIX 返回 ..。 === 语法 === '''pardir()'''方法语法格式如下: <sample title="" desc="" lang="python" hererun="1"> os.pardir </sample> === 参数 === * 无。 === 返回值 === 返回当前目录的父目录,默认值为 ..。 == 以下实例演示了 pardir() 方法的使用: <sample title="" desc="" lang="python" hererun="1"> import os # 输出默认值 .. print(os.pardir) </sample> 执行以上程序输出结果为: <sample title="" desc="" lang="python" hererun="1"> .. </sample> 打印当前目录的父目录: <sample title="" desc="" lang="python" hererun="1"> import os # 当前工作目录 path = os.getcwd() print("当前工作目录: ", path) # 父目录 parent = os.path.join(path, os.pardir) # 父目录 print("\n父目录:", os.path.abspath(parent)) </sample> 执行以上程序输出结果为: <sample title="" desc="" lang="python" hererun="1"> 当前工作目录: /Users/xiaobai/python 父目录: /Users/xiaobai </sample> [[python3 os file methods|Python3 OS 文件/目录方法]]
返回至“
Python3 os pardir
”。
上一节:
Os_write