find the last accessed date of a json file in python

You can use the os.path.getatime() function to retrieve the last access time of a file. Here's an example implementation:

main.py
import os
import json
import datetime

filename = "example.json"
access_time = os.path.getatime(filename)
last_access = datetime.datetime.fromtimestamp(access_time).strftime('%Y-%m-%d %H:%M:%S')

print("Last accessed: ", last_access)
234 chars
10 lines

In the above example, filename should be replaced with the path to your JSON file. The os.path.getatime() function returns the last access time of the file in seconds since epoch, which is then converted to a human-readable format using the datetime module's fromtimestamp() function. The resulting string is printed to the console.

gistlibby LogSnag