YouTip LogoYouTip

Os Mkdir

# Python2.x Python os.mkdir() Method [![Image 3: Python File Methods](#) Python OS File/Directory Methods](#) * * * ### Overview The os.mkdir() method is used to create a directory (single-level directory) with a numeric permission mode. The default mode is 0777 (octal). If the directory has multiple levels, only the last level is created. If the parent directory of the last level does not exist, an OSError will be raised. ### Syntax The syntax for the **mkdir()** method is as follows: os.mkdir(path[, mode]) ### Parameters * **path** -- The directory to be created, which can be a relative or absolute path. * **mode** -- The numeric permission mode to set for the directory. ### Return Value This method does not return a value. ### Example The following example demonstrates the use of the mkdir() method: ## Example #!/usr/bin/python # -*- coding: UTF-8 -*- import os,sys # Directory to be created path ="/tmp/home/monthly/daily/hourly" os.mkdir( path,0755); print"Directory created" The output of the above program is: Directory created [![Image 4: Python File Methods](#) Python OS File/Directory Methods](#)
← Os MkdirOs Makedirs β†’