473,289 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

Retrieving modification time of file class was declared in

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

Jul 18 '05 #1
3 1244
na*****************@yahoo.ca 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
Jul 18 '05 #2
Actually, what my comment wass supposed to say was "Checking the
modification time of the file the Thread class was defined in", but I'm
sure you understood what I meant. ;-)

Orlando Vazquez wrote:
na*****************@yahoo.ca 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 :-)

Jul 18 '05 #3
On 24 Jan 2005 20:39:11 -0800, na*****************@yahoo.ca 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


try this for about any object you can pass to finfo:

----< finfo.py >----------------
import sys, os
def finfo(obj):
if not hasattr(obj, '__name__'):
obj = type(obj)
name = '<%s instance>'%obj.__name__
else:
name = obj.__name__
if type(obj) == type(sys): # module type
modname = name
else: # not module type, but be class now
modname = obj.__module__
mod = sys.modules[modname]
if modname == '__builtin__' or repr(mod) == "<module '%s' (built-in)>"%modname:
path = sys.executable
else:
path = vars(sys.modules[modname]).get('__file__','??')
if path != '??': tmod = os.path.getmtime(path)
else: tmod = '???'
return name, modname, path, tmod
--------------------------------

Not very tested, but seems to retrieve info. The file in question for builtins is
the interpreter executable, I supposed.

Ignore the "ut." here, that's just my utilities grabbag

[ 0:25] C:\pywk\sovm>py24
Python 2.4b1 (#56, Nov 3 2004, 01:47:27)
[GCC 3.2.3 (mingw special 20030504-1)] on win32
Type "help", "copyright", "credits" or "license" for more information.
from ut.finfo import finfo
finfo(finfo) ('finfo', 'ut.finfo', 'c:\\pywk\\ut\\finfo.pyc', 1106641080) import time
time.ctime(finfo(finfo)[-1])

'Tue Jan 25 00:18:00 2005'

HIH

Regards,
Bengt Richter
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Fred | last post by:
Hi ! Can some one give me a little step by step to put me onthe right way.. I'd like to use PHP with Postresql. I need to make many whois query on the domain names that we own, to store the...
3
by: stan | last post by:
I am working on some documentation in html format and I would really like to display the date the html file, itself was modified. I am writing my documentation in vi and the html server involved is...
2
by: Rob Cowie | last post by:
Hi, Given a string representing the path to a file, what is the best way to get at the filename? Does the OS module provide a function to parse the path? or is it acceptable to split the string...
0
by: jim z | last post by:
My goal is to write a program in C# that will take the Artist and Title of an MP3 file and change the name of the file to a concatenated combination of the two. In order to do this, I am trying to...
2
by: ironwall22z | last post by:
My goal is to write a program in C# that will take the Artist and Title of an MP3 file and change the name of the file to a concatenated combination of the two. In order to do this, I am trying to...
5
by: jan axelson | last post by:
My application is using RegisterDeviceNotification() to detect attachment and removal of a USB HID-class device. The form is receiving WM_DEVICECHANGE messages with wParam set to...
16
by: Vijay | last post by:
Hi , Code: #include "iostream.h" void main(void) { const int i=10; int *p; p=const_cast<int*>(&i);
0
by: Olman Quesada | last post by:
Hi everybody, I'm trying to access a TLB in a VB.Net 2005 project. The TLB file is located under c:\windows\system32 directory. However, when a try to instanciate a variable whose type is...
13
by: ts-dev | last post by:
Is it possible to prevent modification of a python file once its been deployed? File permissions of the OS could be used..but that doesn't seem very secure. The root of my question is verifying...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.