Python os.unlink() 方法

Python 教程 · 2019-02-04 13:44:23

概述

os.unlink() 方法用于删除文件,如果文件是一个目录则返回一个错误。

语法

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

os.unlink(path)

参数

  • path -- 删除的文件路径

返回值

该方法没有返回值。

实例

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

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

import os, sys

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

os.unlink("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

查看所有标签

生物序列分析

生物序列分析

Richard Durbin、Sean Eddy、Anders Krogh [等] / 王俊、郭一然、单杲 / 科学出版社 / 2010-8 / 60.00元

生物序列分析,ISBN:9787030284433,作者:(英)Durbin,R 等编著一起来看看 《生物序列分析》 这本书的介绍吧!

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

在线压缩/解压 JS 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换