473,395 Members | 1,452 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,395 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 1248
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.