小白教程
所有教程
关于
Search
172.69.58.241
172.69.58.241
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python3 os remove”的源代码
本页内容
上一节:
Python3_os_readlink
下一节:
Python3_os_removedirs
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:os.remove(path)}}[[Category:python3 os file methods|45]] = Python3 os.remove() 方法 = [[python3 os file methods|Python3 OS 文件/目录方法]] === 概述 === os.remove() 方法用于删除指定路径的文件。如果指定的路径是一个目录,将抛出OSError。 在Unix, Windows中有效 === 语法 === '''remove()'''方法语法格式如下: <sample title="" desc="" lang="python" hererun="1"> os.remove(path) </sample> === 参数 === * '''path''' -- 要移除的文件路径 === 返回值 === 该方法没有返回值 == 以下实例演示了 remove() 方法的使用: <sample title="" desc="" lang="python" hererun="1"> #!/usr/bin/python3 import os, sys # 列出目录 print ("目录为: %s" %os.listdir(os.getcwd())) # 移除 os.remove("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 remove
”。
上一节:
Python3_os_readlink
下一节:
Python3_os_removedirs