Python3 os.fpathconf () method
Python3 OS file / directory methods
Outline
os.fpathconf () method returns an open file system configuration information.
Available on Unix.
grammar
fpathconf () method syntax is as follows:
os.fpathconf(fd, name)
parameter
fd - open file descriptors.
name - optional, and buffersize parameters, and built-in open function, like Python, mode parameter can specify the "r, w, a, r + , w +, a +, b ", etc., indicates that the file is read-only or read-write can , and open files in binary or text form opens.<Stdio.h> These parameters are similar to the C language and the fopen function specified in the mode parameter.
bufsize - retrieve the value of the system configuration, it may be a string of defined system values, these names specified in many standards (POSIX.1, Unix 95, Unix 98 , and others).Some platforms define additional names. These names are in the main operating system on pathconf_names dictionary. For not pathconf_names configuration variables, passing a number as a name, it is also acceptable.
return value
Returns an open file system configuration information.
Examples
The following example demonstrates fpathconf () method of use:
#!/usr/bin/python3 import os, sys # 打开文件 fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT ) print ("%s" % os.pathconf_names) # 获取最大文件连接数 no = os.fpathconf(fd, 'PC_LINK_MAX') print ("文件最大连接数为 :%d" % no) # 获取文件名最大长度 no = os.fpathconf(fd, 'PC_NAME_MAX') print ("文件名最大长度为 :%d" % no) # 关闭文件 os.close( fd ) print ("关闭文件成功!!")
The above program output is:
{'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} 文件最大连接数为 :127 文件名最大长度为 :255 Closed the file successfully!!