Python os.remove() 方法

Python 教程 · 2019-02-04 09:56:33

概述

os.remove() 方法用于删除指定路径的文件。如果指定的路径是一个目录,将抛出OSError。

在Unix, Windows中有效

语法

remove()方法语法格式如下:

os.remove(path)

参数

  • path -- 要移除的文件路径

返回值

该方法没有返回值

实例

以下实例演示了 remove() 方法的使用:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import os, sys

# 列出目录
print "目录为: %s" %os.listdir(os.getcwd())

# 移除
os.remove("aa.txt")

# 移除后列出目录
print "移除后 : %s" %os.listdir(os.getcwd())

执行以上程序输出结果为:

目录为:
[ 'a1.txt','aa.txt','resume.doc' ]
移除后 : 
[ 'a1.txt','resume.doc' ]

点击查看所有 Python 教程 文章: https://codercto.com/courses/l/8.html

查看所有标签

Mastering JavaServer Faces

Mastering JavaServer Faces

Bill Dudney、Jonathan Lehr、Bill Willis、LeRoy Mattingly / Wiley / 2004-6-7 / USD 40.00

Harness the power of JavaServer Faces to create your own server-side user interfaces for the Web This innovative book arms you with the tools to utilize JavaServer Faces (JSF), a new standard that wi......一起来看看 《Mastering JavaServer Faces》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

SHA 加密
SHA 加密

SHA 加密工具