Python3 os.lstat() Method

Python3 OS 文件/目录方法Python3 OS File/Directory Methods


Overview

The os.lstat() method is used to return file information similar to stat(), but without symbolic links. On some platforms, this is an alias for fstat, such as Windows.

Syntax

lstat()The method syntax format is as follows:

os.lstat(path)

Parameters

  • path-- The file for which information is to be returned.

Return Value

Returns file information.

Example

The following example demonstrates the use of the lstat() method:

#!/usr/bin/python3

import os, sys

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

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

# 获取元组
info = os.lstat(path)

print ("文件信息 :", info)

# 获取文件 uid
print ("文件 UID  :%d" % info.st_uid)

# 获取文件 gid
print ("文件 GID :%d" % info.st_gid)

The output of the above program is:

文件信息 : (33261, 3450178L, 103L, 1, 500, 500, 0L, 
             1238866944, 1238866944, 1238948312)
文件 UID :500
文件 GID :500

Python3 OS 文件/目录方法Python3 OS File/Directory Methods

Other Extensions