
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
- Python Useful Resources
- Python - Questions and Answers
- Python - Quick Guide
- Python - Tools/Utilities
- Python - Useful Resources
- Python - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python os.utime() Method
Description
Python method utime() sets the access and modified times of the file specified by path.
Syntax
Following is the syntax for utime() method −
os.utime(path, times)
Parameters
path − This is the path of the file.
times − This is the file access and modified time. If times is none, then the file access and modified times are set to the current time. The parameter times consists of row in the form of (atime, mtime) i.e (accesstime, modifiedtime).
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!!"
When we run above program, it produces 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!!
python_files_io.htm
Advertisements