Retrieving modification time of file class was declared in

Orlando Vazquez ovazquez at
Tue Jan 25 00:22:05 EST 2005

nathan_kent_bullock at wrote:
> Assume I am using a class Foo. I want to find out the modification time
> of the file that that class was defined in. How would I go about this?
> If I could find out the name of the file that Foo was defined in then
> it is easy, I could use os.path.getmtime(), but I can't even figure
> that out.
> I realize that this wouldn't be a completely accurate way to tell the
> last time this class was modified because it could inherit info from
> other classes, or use functions from other modules that have been
> modified, etc.
> Nathan Bullock

Off the top of my head, without having done too much experimentation 
here's what you could try. Caveat: there may be a more robust/cleaner 
way of doing this:

# Checking the modificationtime of the Thread class in the threading
# module

 >>> import threading
 >>> import time
 >>> module_filename = vars()[threading.Thread.__module__].__file__
 >>> mtime = os.path.getmtime(module_filename)
 >>> print time.ctime(mtime)
Sun Nov 14 20:29:42 2004

I hope that answer's your question :-)

Orlando Vazquez

More information about the Python-list mailing list