using inspect

Ethan Furman ethan at stoneleaf.us
Wed Nov 11 21:15:22 EST 2009


Greetings!

How wise is it to base code on inspect?  Specifically on things like 
live frames on the stack and whatnot.  It occurs to me that this is 
leaning towards implementation details, and away from pure, pristine Python.

As an example, I have this routine in a module I'm working on:

def _get_module():
     "get the calling module -- should be the config'ed module"
     target = os.path.splitext(inspect.stack()[2][1])[0]
     target = __import__(target)
     return target

How brittle is this technique?

~Ethan~



More information about the Python-list mailing list