描述
方法pathconf()返回與命名文件相關的係統配置信息。
用法
以下是語法pathconf()方法 -
os.pathconf(path, name)
參數
path- 這是文件路徑。
name- 指定要檢索的配置值;它可能是一個字符串,它是定義的係統值的名稱;這些名稱在許多標準(POSIX.1、Unix 95、Unix 98 等)中都有規定。主機操作係統已知的名稱在os.pathconf_names字典。
返回值
此方法返回文件的係統配置信息。在類 Unix 係統上可用
示例
下麵的例子展示了 pathconf() 方法的用法。
#!/usr/bin/python3
import os, sys
print ("%s" % os.pathconf_names)
# Retrieve maximum length of a filename
no = os.pathconf('a2.py', 'PC_NAME_MAX')
print ("Maximum length of a filename:%d" % no)
# Retrieve file size
no = os.pathconf('a2.py', 'PC_FILESIZEBITS')
print ("file size in bits :%d" % no)
結果
當我們運行上述程序時,它會產生以下結果 -
{'PC_MAX_INPUT':2, 'PC_VDISABLE':8, 'PC_SYNC_IO':9, 'PC_SOCK_MAXBUF':12, 'PC_NAME_MAX':3, 'PC_MAX_CANON':1, 'PC_PRIO_IO':11, 'PC_CHOWN_RESTRICTED':6, 'PC_ASYNC_IO':10, 'PC_NO_TRUNC':7, 'PC_FILESIZEBITS':13, 'PC_LINK_MAX':0, 'PC_PIPE_BUF':5, 'PC_PATH_MAX':4} Maximum length of a filename:255 file size in bits:64
相關用法
- Python 3 os.popen()用法及代碼示例
- Python 3 os.pipe()用法及代碼示例
- Python 3 os.fstatvfs()用法及代碼示例
- Python 3 os.minor()用法及代碼示例
- Python 3 os.close()用法及代碼示例
- Python 3 os.unlink()用法及代碼示例
- Python 3 os.major()用法及代碼示例
- 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.makedirs()用法及代碼示例
- Python 3 os.utime()用法及代碼示例
- Python 3 os.tcgetpgrp()用法及代碼示例
- Python 3 os.statvfs()用法及代碼示例
- Python 3 os.lchown()用法及代碼示例
- Python 3 os.mknod()用法及代碼示例
注:本文由純淨天空篩選整理自 Python 3 - os.pathconf() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。