Python os.pathconf() 方法

Python 教程 · 2019-02-04 08:44:10

概述

os.pathconf() 方法用于返回一个打开的文件的系统配置信息。

Unix 平台下可用。

语法

fpathconf()方法语法格式如下:

os.fpathconf(fd, name)

参数

  • name -- 文件描述符

  • name -- 检索的系统配置的值,它也许是一个定义系统值的字符串,这些名字在很多标准中指定(POSIX.1, Unix 95, Unix 98, 和其它)。一些平台也定义了一些额外的名字。这些名字在主操作系统上pathconf_names的字典中。对于不在pathconf_names中的配置变量,传递一个数字作为名字,也是可以接受的。

  • 返回值

    返回文件的系统信息。

    实例

    以下实例演示了 fpathconf() 方法的使用:

    #!/usr/bin/python
    # -*- coding: UTF-8 -*-
    
    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 "Maximum number of links to the file. :%d" % no
    
    # 获取文件名最大长度
    no = os.fpathconf(fd, 'PC_NAME_MAX')
    print "Maximum length of a filename :%d" % no
    
    # 关闭文件
    os.close( fd)
    
    print "关闭文件成功!!"
    

    执行以上程序输出结果为:

    关闭文件成功!!
    

    点击查看所有 Python 教程 文章: https://codercto.com/courses/l/8.html

    查看所有标签

    PHP for the World Wide Web, Second Edition (Visual QuickStart Gu

    PHP for the World Wide Web, Second Edition (Visual QuickStart Gu

    Larry Ullman / Peachpit Press / 2004-02-02 / USD 29.99

    So you know HTML, even JavaScript, but the idea of learning an actual programming language like PHP terrifies you? Well, stop quaking and get going with this easy task-based guide! Aimed at beginning ......一起来看看 《PHP for the World Wide Web, Second Edition (Visual QuickStart Gu》 这本书的介绍吧!

    CSS 压缩/解压工具
    CSS 压缩/解压工具

    在线压缩/解压 CSS 代码

    随机密码生成器
    随机密码生成器

    多种字符组合密码

    html转js在线工具
    html转js在线工具

    html转js在线工具