Python os.makedirs() 方法

Python 教程 · 2019-02-04 06:59:25

概述

os.makedirs() 方法用于递归创建目录。像 mkdir(), 但创建的所有intermediate-level文件夹需要包含子目录。

语法

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

os.makedirs(path, mode=0o777)

参数

  • path -- 需要递归创建的目录。

  • mode -- 权限模式。

返回值

该方法没有返回值。

实例

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

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

import os, sys

# 创建的目录
path = "/tmp/home/monthly/daily"

os.makedirs( path, 0755 );

print "路径被创建"

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

路径被创建

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

查看所有标签

The Elements of Statistical Learning

The Elements of Statistical Learning

Trevor Hastie、Robert Tibshirani、Jerome Friedman / Springer / 2009-10-1 / GBP 62.99

During the past decade there has been an explosion in computation and information technology. With it have come vast amounts of data in a variety of fields such as medicine, biology, finance, and mark......一起来看看 《The Elements of Statistical Learning》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具