OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is sub module of OS module in Python used for common path name manipulation.
os.path.getmtime() method in Python is used to get the time of last modification of the specified path. This method returns a floating point value which represents the number of seconds since the epoch. This method raise OSError if the file does not exist or is somehow inaccessible.
Note: The epoch represents the point where the time starts. It is platform dependent. For Unix, the epoch is January 1, 1970, 00:00:00 (UTC).
path: A path-like object representing a file system path. A path-like object is either a string or bytes object representing a path.
Return Type: This method returns a floating-point value of class ‘float’ that represents the time (in seconds) of last modification of the specified path.
Code #1: Use of os.path.getmtime() method
Last modification time since the epoch: 1558447897.0442736 Last modification time (Local time): Tue May 21 19:41:37 2019
Code #2: Handling error while using os.path.getmtime() method
Path '/home/User/Documents/file2.txt' does not exists or is inaccessible
- class method vs static method in Python
- Python | set() method
- Python | next() method
- Python | os.dup() method
- Python | os.getpgid() method
- Python | os.tcgetpgrp() method
- Python | PyTorch tan() method
- Python | os.scandir() method
- Python | os.strerror() method
- Python | os.readlink() method
- Python | os.writev() method
- Python | sympy.Add() method
- Python | sympy.Mul() method
- Python PIL | ImageOps.fit() method
- Python | os.getppid() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.