date formatting

Jeremy Dillworth jwdillworth at
Fri Sep 12 20:37:22 CEST 2003

This works, with Python 2.3:

from datetime import datetime

It leaves out the call to localtime, but now you're constructing a 
datetime object, so it's really not more direct.  Some may find it
more readable, or at least I think it is, er... well slightly :)

On Linux os.stat() returns an object of type posix.stat_result,
I wonder if this type could be enhanced so that one could do this:


(mdatetime returning a datetime object)

Naturally we'd probably want os.stat('thefile').cdatetime and so 
on too...

--- WmGill <wmgill at> wrote:
> I want to write a script that Among other things) renames a file based on
> it's timestamp.
> I can get the date info using
> "strftime('%y%m%d',localtime(os.stat('thefile')[ST_MTIME])", but this seems
> like a long way around the block.  Is there a more direct way?
> Bill
> -- 

More information about the Python-list mailing list