OS File 中的 os.lstat(path)函数

首页 / Python2入门教程 / OS File 中的 os.lstat(path)函数

Python方法lstat()与fstat()非常相似,并返回有关文件的信息,但不遵循符号链接。这是不支持符号链接的平台(如Windows)上fstat()的别名。

下面是lstat方法-返回的结构

  • st_dev        -  包含文件的设备的ID

  • st_ino        -  信息节点编号

  • st_mode    -  保护

  • st_nlink     -  硬链接数量

  • st_uid         -  所有者的用户ID

  • st_gid         -  所有者的组ID

  • st_rdev       -  设备ID(如果是特殊文件)

  • st_Size        -  总大小,以字节为单位

  • st_blksize   - 文件系统I/O的-块大小

  • st_blocks    -  已分配的块数

  • st_atime     -  上次访问时间

  • st_mtime    -  上次修改的时间

  • st_ctime      -  上次状态更改的时间

os.lstat(path) - 语法

os.lstat(path)
  • path  -  这是将返回其信息的文件。

os.lstat(path) - 返回值

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

os.lstat(path) - 示例

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

#!/usr/bin/python

import os, sys

# 打开文件
path="/var/www/html/foo.txt"
fd=os.open( path, os.O_RDWR|os.O_CREAT )

# 关闭已打开的文件
os.close( fd )

# Now get  the touple
info=os.lstat(path)

print "File Info :", info

# 现在得到文件的UID
print "UID of the file :%d" % info.st_uid

# 现在获取文件的GID
print "GID of the file :%d" % info.st_gid

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

File Info : (33261, 3450178L, 103L, 1, 500, 500, 0L, 
             1238866944, 1238866944, 1238948312)
UID of the file :500
GID of the file :500

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

微服务架构核心20讲 -〔杨波〕

技术领导力实战笔记 -〔TGO鲲鹏会〕

从0开始学游戏开发 -〔蔡能〕

白话法律42讲 -〔周甲徳〕

从0开始做增长 -〔刘津〕

从0开发一款iOS App -〔朱德权〕

TensorFlow 2项目进阶实战 -〔彭靖田〕

用户体验设计实战课 -〔相辉〕

容器实战高手课 -〔李程远〕

好记忆不如烂笔头。留下您的足迹吧 :)