Python3 os.mkdir() Method
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
-
path -- The directory to create; it can be a relative or absolute path.
-
mode -- The numeric permission mode to set for the directory
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
)
(
"Directory created"
)
The output of the above program is:
目录已创建