finding the file of a module from inside a class

Thomas Weholt thomas at gatsoft.no
Tue Sep 25 04:58:32 EDT 2001


say I got a module test.py with this content:

class MyClass:
    def __init__(self):
        pass
    def myfile(self):
        return '' # ????

if I put this into a folder, ex. /home/thomas/dev/test/, how can I get
information about what file the code instance actually is stored in, from
inside my class? I want the myfile-method to return
/home/thomas/dev/test/test.py ( if the class is stored in a module called
test.py in a folder /home/thomas/dev/test/ of course ).

What I want is to have a config-file in the same folder as my test.py, so
when my class is used it reads the config automatically. This has to be done
dynamically, no hardcoded data, and no need for the user to provide paths to
files etc.

Thomas





More information about the Python-list mailing list