Python os.lstat()方法

Python的lseek()方法与fstat()非常相似,并返回一个包含有关文件信息的stat_result对象,但不要跟随符号链接。这是在不支持符号链接的平台上的fstat()的别名,例如:Windowsphp基础知识

这是lstat方法返回的结构 -

  • st_dev - 包含文件的设备的ID
  • st_ino - inode编号
  • 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 - 上次状态更改的时间

语法

以下是lstat()方法的语法 -

Python
os.lstat(path)

参数

  • path - 这是文件描述符,需要处理。

定义的pos常数 -

  • os.SEEK_SET = 0
  • os.SEEK_CUR = 1
  • os.SEEK_END = 2

返回值

  • 这是要返回信息的文件。

示例

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

Python
#!/usr/bin/python3
import os, sys

# Open a file
path = "d:\python3\foo.txt"
fd = os.open( path, os.O_RDWR|os.O_CREAT )

# Close opened file
os.close( fd )

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

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)

执行上面代码后,将得到以下结果 -

Python
File Info : os.stat_result(st_mode=33206, st_ino=281474976797706, st_dev=1017554828, st_nlink=2, st_uid=0, st_gid=0, st_size=13, st_atime=1455597777, st_mtime=1438077266, st_ctime=1455560006)
UID of the file :0
GID of the file :0
原文地址:https://www.cnblogs.com/furuihua/p/14529468.html