如何使用Python获取与打开的文件相关的系统配置信息?
您可以调用fpathconf(file_descriptor,name)函数来获取与打开的文件有关的系统配置信息。名称指定要检索的配置值;它可以是一个字符串,它是定义的系统值的名称;这些名称在许多标准中都有规定。请注意,此功能仅在Unix系统上可用。例如,
import os, sys # Open a file fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT ) # 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 os.close( fd)
当我们运行上面的程序时,它产生以下结果:
Maximum number of links to the file. :127 Maximum length of a filename :255
热门推荐
10 病人祝福语老师寄语简短
11 新娘生孩子祝福语简短
12 婆婆66岁祝福语简短
13 今天孩子高考祝福语简短
14 送彩票生日祝福语简短
15 分别祝福语简短情话英文
16 画室揭牌仪式祝福语简短
17 女友妈妈生日祝福语简短
18 离别赠言离职祝福语简短