28.10.2021 Views

Python Tutorial ( PDFDrive )

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

print "Closed the file successfully!!"

Let us compile and run the above program, this will produce the following result:

Read String is : This is test

Closed the file successfully!!

os.lstat(path)

Description

The method lstat() is very similar to fstat() and returns the information about a file, but do not follow symbolic

links. This is an alias for fstat() on platforms that do not support symbolic links, such as Windows.

Here is the structure returned by lstat method:

• st_dev: ID of device containing file

• st_ino: inode number

• st_mode: protection

• st_nlink: number of hard links

• st_uid: user ID of owner

• st_gid: group ID of owner

• st_rdev: device ID (if special file)

• st_size: total size, in bytes

• st_blksize: blocksize for filesystem I/O

• st_blocks: number of blocks allocated

• st_atime: time of last access

• st_mtime: time of last modification

• st_ctime: time of last status change

Syntax

Following is the syntax for lstat() method:

os.lstat(path)

Parameters

• path -- This is the file for which information would be returned.

Return Value

This method returns the information about a file.

Example

The following example shows the usage of lstat() method.

#!/usr/bin/python

import os, sys

# Open a file

path = "/var/www/html/foo.txt"

fd = os.open( path, os.O_RDWR|os.O_CREAT )

TUTORIALS POINT

Simply Easy Learning

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!