find the last modified date of a csv file in python

You can use the os.path.getmtime() function to get the last modified timestamp of a file, and then convert it to a human-readable date format using the datetime module. Here's an example code:

main.py
import os
import datetime

filename = "example.csv"
timestamp = os.path.getmtime(filename)
last_modified_date = datetime.datetime.fromtimestamp(timestamp)

print("Last modified date of", filename, "is", last_modified_date)
223 chars
9 lines

This code will print something like:

main.py
Last modified date of example.csv is 2022-01-28 14:36:47.501425
64 chars
2 lines

Note that the fromtimestamp() function returns a datetime object, which you can format as a string using various methods.

gistlibby LogSnag