Python os.rmdir() 方法

Python 教程 · 2019-02-04 10:59:15

概述

os.rmdir() 方法用于删除指定路径的目录。仅当这文件夹是空的才可以, 否则, 抛出OSError。

语法

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

os.rmdir(path)

参数

  • path -- 要删除的目录路径

返回值

该方法没有返回值

实例

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

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

import os, sys

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

# 删除路径
os.rmdir("mydir")

# 列出重命名后的目录
print "目录为: %s" %os.listdir(os.getcwd())

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

目录为:
[  'a1.txt','resume.doc','a3.py','mydir' ]
目录为:
[  'a1.txt','resume.doc','a3.py' ]

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

查看所有标签

Algorithms and Theory of Computation Handbook

Algorithms and Theory of Computation Handbook

Mikhail J. Atallah (Editor) / CRC-Press / 1998-09-30 / USD 94.95

Book Description This comprehensive compendium of algorithms and data structures covers many theoretical issues from a practical perspective. Chapters include information on finite precision issues......一起来看看 《Algorithms and Theory of Computation Handbook》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具