无涯教程-OS File - os.fstat(fd)函数

64 阅读1分钟

Python方法fstat()返回有关与FD关联的文件的信息。

    os.fstat(fd) - 语法

    os.fstat(fd)
    • fd  -  这是要返回其系统信息的文件描述符。

    os.fstat(fd) - 返回值

    此方法返回有关与FD关联的文件的信息。

    os.fstat(fd) - 示例

    以下示例显示了chdir()方法的用法。

    #!/usr/bin/python
    

    import os, sys

    # Open a file fd=os.open( "foo.txt", os.O_RDWR|os.O_CREAT )

    # Now get the touple info=os.fstat(fd)

    print "File Info :", info

    # Now get uid of the file print "UID of the file :%d" % info.st_uid

    # Now get gid of the file print "GID of the file :%d" % info.st_gid

    # Close opened file os.close( fd)

    当无涯教程运行上面的程序时,它产生以下输出-

    File Info : (33261, 3753776L, 103L, 1, 0, 0, 
                102L, 1238783197, 1238786767, 1238786767)
    UID of the file :0
    GID of the file :0

    参考链接

    www.learnfk.com/python/os-f…