Finding the calling method (or caller)

Chad Netzer cnetzer at mail.arc.nasa.gov
Fri Jan 17 15:23:20 EST 2003


On Friday 17 January 2003 10:43, Aahz wrote:
> In article <mailman.1042767154.29348.python-list at python.org>,
>
> Chad Netzer  <cnetzer at mail.arc.nasa.gov> wrote:
> >On Thursday 16 January 2003 16:56, Aahz wrote:
> >> Why do you want to know this?  There's likely to be a better way
> >> than using sys._getframe().
> >
> >I use introspection techniques like this to enforce calling through
> > the "public" api, and not the private.
>
> Why not just use methods with leading underscores?

True; that is the kind of name mangling I refered obliquely to.  I 
prefer my method, just because it seems to fit my style of design well 
(build an internal API as one goes along, refactor it a lot, then 
expose it when it is reasonable).  The call chanin enforcement was 
easier to code than all the potential renaming, I guess.

Actually, now that I've discovered Bicycle Repair Man, that kind of 
thing is easier to do (method renames, class renames, etc.)

I mainly mentioned it becuase the technique does have some merit, 
depending on one's design style.

-- 
Bay Area Python Interest Group - http://www.baypiggies.net/

Chad Netzer






More information about the Python-list mailing list