Latest web development tutorials

Python os.lstat () method

Python File (File) method Python OS file / directory methods


Outline

os.lstat () method used is similar to stat () returns a file, but not a symbolic link. On some platforms, this is fstat alias, such as Windows.

grammar

lstat () method syntax is as follows:

os.lstat(path)

parameter

  • path - to return file information.

return value

File information is returned.

Examples

The following example demonstrates lstat () method of use:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

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 above program output is:

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

Python File (File) method Python OS file / directory methods