如何使用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
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短