Latest web development tutorials

Python3 os.mknod () method

Python3 OS file / directory methods Python3 OS file / directory methods


Outline

Filesystem node (file, device special file or named pipe) os.mknod () method is used to create a specified file name.

grammar

mknod () method syntax is as follows:

os.mknod(filename[, mode=0600[, device=0]])

parameter

  • filename - the file system created node

  • mode - mode specifies the permissions to create or use a node, a combination (or bitwise) stat.S_IFREG, stat.S_IFCHR, stat.S_IFBLK, and stat.S_IFIFO (these constants in the stat module) for stat.S_IFCHR and stat.S_IFBLK,. device defines the newly created device special file (probably using os.makedev ()), the other will be ignored.

  • device - optional equipment to create the file specified

return value

This method has no return value.

Examples

The following example demonstrates mknod () method of use:

#!/usr/bin/python3

import os
import stat

filename = '/tmp/tmpfile'
mode = 0600|stat.S_IRUSR

# 文件系统节点指定不同模式
os.mknod(filename, mode)

The above program output is:

-rw-------. 1 root   root         0 Apr 30 02:38 tmpfile

Python3 OS file / directory methods Python3 OS file / directory methods