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.

Return Value

This method does not return any value.

Example

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

# !/usr/bin/python

import os, sys

# Showing stat information of file

stinfo = os.stat('a2.py')

print stinfo

# Using os.stat to recieve atime and mtime of file

print "access time of a2.py: %s" %stinfo.st_atime

print "modified time of a2.py: %s" %stinfo.st_mtime

# Modifying atime and mtime

os.utime("a2.py",(1330712280, 1330712292))

print "done!!"

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

posix.stat_result(st_mode=33188, st_ino=3940649674337682L, st_dev=277923425L, st

_nlink=1, st_uid=400, st_gid=401, st_size=335L, st_atime=1330498070, st_mtime=13

30498074, st_ctime=1330498065)

access time of a2.py: 1330498070

modified time of a2.py: 1330498074

done!!

os.walk(top[, topdown=True[, onerror=None[,

followlinks=False]]])

Description

The method walk() generates the file names in a directory tree by walking the tree either top-down or bottom-up.

Syntax

Following is the syntax for walk() method:

os.walk(top[, topdown=True[, onerror=None[, followlinks=False]]])

Parameters

• top -- Each directory rooted at directory, yields 3-tuples, i.e., (dirpath, dirnames, filenames)

• topdown -- If optional argument topdown is True or not specified, directories are scanned from top-down. If

topdown is set to False, directories are scanned from bottom-up.

• onerror -- This can show error to continue with the walk, or raise the exception to abort the walk.

• followlinks -- This visits directories pointed to by symlinks, if set to true.

Return Value

This method does not return any value.

TUTORIALS POINT

Simply Easy Learning

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

Saved successfully!

Ooh no, something went wrong!