os.path.getatime() in Python is used to get the last access time to a specified path. This method returns a floating point value that represents the number of seconds since the beginning of the epoch. This method raises an OSError if the file does not exist or is not available.
Note: The epoch represents the point where time begins. It depends on the platform. For Unix, the era of — January 1, 1970 00:00:00 UTC.
Syntax: os.path.getatime (path) p>
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 access of the specified path.
Code # 1 : Using the os.path.getatime () method
Last access time since the epoch: 1558447897.0442736 Last access time (Local time): Tue May 21 19:41:37 2019
Code # 2: Error handling when using the os.path.getatime () method
p > Exit:
# Python program to explain the method os.path.getatime ()
# import os, time module and systems
`/ home / User / Documents / file2.txt` p>
# Get last time
# access to the specified
# path from the era
"Last access time since the epoch:"
"Path`% s` does not exists or is inaccessible "
# convert time to
# seconds since the beginning of the epoch
# local time
local_time code >
"Last access time (Local time):"
# the code above will print
# "The file does not exist or is not available"
# if the specified path is not
# exists or is not available
Path `/ home / User / Documents / file2.txt` does not exists or is inaccessible
This book contains chapters authored by several leading experts in the field of cloud computing. The book is presented in a coordinated and integrated manner starting with the fundamentals and followe...
A Practical Approach to Computer Algorithms Using Python® and C# Rod Stephens started out as a mathematician, but while studying at MIT, he discovered how much fun algorithms are. He took every al...
Roger Jennings is an author and consultant specializing in Microsoft .NET n-tier database applications and data-intensive Windows Communication Foundation (WCF) Web services with SQL Server. He’s be...
The Pragmatic Programmer: Your Journey To Mastery, 20th Anniversary Edition (2nd Edition). The Pragmatic Programmer is one of those rare technical books that you will read, reread, and re-read over...