Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the time a file was last modified in Python? [duplicate]

Tags:

python

file

time

Assuming the file exists (using os.path.exists(filename) to first make sure that it does), how do I display the time a file was last modified? This is on Linux if that makes any difference.

like image 540
Bill the Lizard Avatar asked Dec 17 '08 16:12

Bill the Lizard


People also ask

Which function is used to get the last modification time?

Using getlastmod() Function: The getlastmod() function is used to get the last modification time of the current page.

When was a file last modified?

The File. lastModified read-only property provides the last modified date of the file as the number of milliseconds since the Unix epoch (January 1, 1970 at midnight). Files without a known last modified date return the current date.

How do you tell the time of a file in Python?

Method 1: Get file creation & modification date or time in Python using the time module. We will use getctime() and getmtime() function found inside the path module in the os library, for getting the creation and modification times of the file.


1 Answers

>>> import os >>> f = os.path.getmtime('test1.jpg') >>> f 1223995325.0 

since the beginning of (epoch)

like image 142
Jack Avatar answered Sep 21 '22 09:09

Jack