Os Fpathconf
# Python2.x Python os.fpathconf() Method
[ Python OS File/Directory Methods](#)
* * *
### Overview
The os.fpathconf() method is used to return system configuration information for an open file.
Available on Unix.
### Syntax
The syntax for the **fpathconf()** method is as follows:
os.fpathconf(fd, name)
### Parameters
* **fd** -- The file descriptor of the open file.
* **name** -- Optional, similar to the buffersize parameter and Python's built-in open function, the mode parameter can specify 'r, w, a, r+, w+, a+, b', indicating whether the file is read-only or read-write, and whether the file is opened in binary or text mode. These parameters are similar to the mode parameter specified in the fopen function in C's .
* **bufsize** -- The value of the system configuration to retrieve. It may be a string defining a system value, specified in many standards (POSIX.1, Unix 95, Unix 98, and others). Some platforms also define additional names. These names are in the pathconf_names dictionary on the main operating system. For configuration variables not in pathconf_names, passing a number as the name is also acceptable.
### Return Value
Returns system configuration information for an open file.
### Example
The following example demonstrates the use of the fpathconf() method:
#!/usr/bin/python# -*- coding: UTF-8 -*-import os, sys # Open file fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )print "%s" % os.pathconf_names # Get maximum number of file links = os.fpathconf(fd, 'PC_LINK_MAX')print "Maximum number of file links is :%d" % no# Get maximum filename length = os.fpathconf(fd, 'PC_NAME_MAX')print "Maximum filename length is :%d" % no# Close file os.close( fd )print "File closed successfully!!"
The output of executing the above program 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}Maximum number of file links is :127Maximum filename length is :255Closed the file successfully!!
[ Python OS File/Directory Methods](#)
YouTip