如何使用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 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短