描述
方法mknod()創建一個名為 filename 的文件係統節點(文件、設備專用文件或命名管道)。
用法
以下是語法mknod()方法 -
os.mknod(filename[, mode = 0600[, device = 0]])
參數
filename- 這是要創建的文件係統節點。
mode− 模式指定要使用的權限和要創建的節點類型,並與 stat.S_IFREG、stat.S_IFCHR、stat.S_IFBLK 和 stat.S_IFIFO 值之一組合(按位或)。他們可以根據需求進行 ORed。
device- 這是創建的設備專用文件,可以選擇提供。
返回值
此方法不返回任何值。在類 Unix 係統上可用
示例
下麵的例子展示了 mknod() 方法的用法。
# !/usr/bin/python3
import os
import stat
filename = '/tmp/tmpfile'
mode = 0600|stat.S_IRUSR
# filesystem node specified with different modes
os.mknod(filename, mode)
結果
讓我們編譯並運行上麵的程序,這將在 /tmp 目錄中創建一個名為 tmpfile 的簡單文件 -
-rw-------. 1 root root 0 Apr 30 02:38 tmpfile
相關用法
- Python 3 os.mkdir()用法及代碼示例
- Python 3 os.mkfifo()用法及代碼示例
- Python 3 os.minor()用法及代碼示例
- Python 3 os.major()用法及代碼示例
- Python 3 os.makedirs()用法及代碼示例
- Python 3 os.makedev()用法及代碼示例
- Python 3 os.fstatvfs()用法及代碼示例
- Python 3 os.close()用法及代碼示例
- Python 3 os.unlink()用法及代碼示例
- Python 3 os.rmdir()用法及代碼示例
- Python 3 os.fdopen()用法及代碼示例
- Python 3 os.fdatasync()用法及代碼示例
- Python 3 os.isatty()用法及代碼示例
- Python 3 os.rename()用法及代碼示例
- Python 3 os.walk()用法及代碼示例
- Python 3 os.renames()用法及代碼示例
- Python 3 os.utime()用法及代碼示例
- Python 3 os.tcgetpgrp()用法及代碼示例
- Python 3 os.statvfs()用法及代碼示例
- Python 3 os.lchown()用法及代碼示例
注:本文由純淨天空篩選整理自 Python 3 - os.mknod() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。