Python3 os.fpathconf()方法

mpathconf()方法返回相关的一个打开的文件系统配置信息。这个变量是非常相似 UNIX系统 mpathconf()调用和接受类似的参数。

语法

以下是 mpathconf()方法的语法:
os.fpathconf(fd, name)

参数

  • fd -- 这是将被返回系统配置信息的文件描述符

  • name -- 这指定配置值用于检索; 它可以是一个字符串,它是一个定义的系统值的名称; 这些名称在若干标准(POSIX.1,Unix的95,Unix的98,及其他)指定。主机操作系统的名称在 os.pathconf 名称字典中给出。

返回值

此方法返回有关一个打开的文件系统的配置信息。

示例

下面的示例显示 mpathconf()方法的使用。
#!/usr/bin/python3

import os, sys

# Open a file
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )

print ("%s" % os.pathconf_names)

# Now get maximum number of links to the file.
no = os.fpathconf(fd, 'PC_LINK_MAX')
print ("Maximum number of links to the file. :%d" % no)

# Now get maximum length of a filename
no = os.fpathconf(fd, 'PC_NAME_MAX')
print ("Maximum length of a filename :%d" % no)

# Close opened file
os.close( fd)

print ("Closed the file successfully!!")
当我们运行上面的程序,它会产生以下结果:
{'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 number of links to the file. :127
Maximum length of a filename :255
Closed the file successfully!!


上一篇: Python3文件方法 下一篇: Python3 os文件目录的方法