Python| os.mknod() 方法
Python中的OS 模块提供了与操作系统交互的功能。操作系统属于 Python 的标准实用程序模块。该模块提供了一种使用操作系统相关功能的可移植方式。
Python中的os.mknod()方法用于创建文件系统节点,即具有指定路径名的文件、设备专用文件或命名管道。
Syntax: os.mknod(path, mode = 0o600, device = 0, *, dir_fd = None)
Parameters:
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.
代码: os.mknod()方法的使用
Python3
# Python3 program to explain os.mknod() method
# importing os module
import os
# importing stat module
import stat
# Path
path = "filex.txt"
# Permission to use
per = 0o600
# type of node to be created
node_type = stat.S_IRUSR
mode = per | node_type
# Create a file system node
# with specified permission
# and type using
# os.mknod() method
os.mknod(path, mode)
print("Filesystem node is created successfully")
输出:
File system node is created successfully