小白教程
所有教程
关于
Search
172.70.126.111
172.70.126.111
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python3 os unlink”的源代码
本页内容
上一节:
Python3_os_ttyname
下一节:
Python3_os_utime
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:os.unlink(path)}}[[Category:python3 os file methods|57]] = Python3 os.unlink() 方法 = [[python3 os file methods|Python3 OS 文件/目录方法]] === 概述 === os.unlink() 方法用于删除文件,如果文件是一个目录则返回一个错误。 === 语法 === '''unlink()'''方法语法格式如下: <sample title="" desc="" lang="python" hererun="1"> os.unlink(path) </sample> === 参数 === * '''path''' -- 删除的文件路径 === 返回值 === 该方法没有返回值。 == 以下实例演示了 unlink() 方法的使用: <sample title="" desc="" lang="python" hererun="1"> #!/usr/bin/python3 import os, sys # 列出目录 print ("目录为: %s" %os.listdir(os.getcwd())) os.unlink("aa.txt") # 删除后的目录 print ("删除后的目录为 : %s" %os.listdir(os.getcwd())) </sample> 执行以上程序输出结果为: <sample title="" desc="" lang="python" hererun="1"> 目录为: [ 'a1.txt','aa.txt','resume.doc'] 删除后的目录为 : [ 'a1.txt','resume.doc' ] </sample> [[python3 os file methods|Python3 OS 文件/目录方法]]
返回至“
Python3 os unlink
”。
上一节:
Python3_os_ttyname
下一节:
Python3_os_utime