Python | os.mknod () method

Python Methods and Functions

os.mknod() in Python is used to create a file system node, that is, a file, device special file, or named pipe with the specified pathname.

Syntax: os.mknod (path, mode = 0o600, device = 0, *, dir_fd = None)

path: A path-like object representing the file system path.
device (optional): This defines the newly created device files. The default value of this parameter is 0.
dir_fd (optional): This is a file descriptor referring to a directory.

Return type: This method does not return any value.

Code: using method os.mknod ()

# Python3 program to explain the os.mknod () method

# import of the os module

import os

# import of statistics module

import stat


# Path

path = "filex.txt"

# Permission to use

per = 0o600

# type of node to create

node_type = stat.S_IRUSR 

mode = per | node_type

# Create system file node
# with the specified resolution
# and enter using
# os.mknod () method
os.mknod (path, mode)


print ( "Filesystem node is created successfully " )

Exit :

 File system node is created successfully 

Get Solution for free from DataCamp guru