Time in python

Ken Seehof kseehof at neuralintegrator.com
Thu May 30 21:13:32 EDT 2002


Gold Fish asks:
> Can anyone tell me how we seperate the time in the file name in python.
> For example 
> python.txt 28/05/02 06:25

    import os
    atime, mtime, ctime = os.stat('python.txt')[-3:]

The last three items returned by os.stat are:
 atime = most recent access
 mtime = most recent modification
 ctime = most recent content/metadata change

The times are in seconds from the epoch.  To convert to human readable
form, use the time module:

    import time
    time.asctime(time.localtime(mtime))


Also, see os.fstat (for files that are opened).

- Ken Seehof






More information about the Python-list mailing list