Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python3 os.mkdir() Method

Python3 os.mkdir() Method

Python3 OS File/Directory Methods Python3 OS File/Directory Methods


Overview

The os.mkdir() method creates a directory with a numeric permission mode. The default mode is 0777 (octal).

If the path has multiple levels, only the last level is created; if a parent directory of that last level does not exist, an OSError is raised.

Syntax

The **mkdir()** method syntax is as follows:


os.mkdir(path[, mode])

Parameters

Return Value

This method has no return value.

Example

The following example demonstrates the use of the mkdir() method:

Example

#!/usr/bin/python

-- coding: UTF-8 --

import

os

,

sys

The directory to create

path

=

"/tmp/home/monthly/daily/hourly"

os

.

mkdir

(

path

,

0755

)

print

(

"Directory created"

)

The output of the above program is:


目录已创建

Python3 OS File/Directory Methods Python3 OS File/Directory Methods