Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #35136 > unrolled thread

Re: context aware execution

Started byChris Angelico <rosuav@gmail.com>
First post2012-12-20 03:07 +1100
Last post2012-12-20 03:07 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: context aware execution Chris Angelico <rosuav@gmail.com> - 2012-12-20 03:07 +1100

#35136 — Re: context aware execution

FromChris Angelico <rosuav@gmail.com>
Date2012-12-20 03:07 +1100
SubjectRe: context aware execution
Message-ID<mailman.1059.1355933279.29569.python-list@python.org>
On Thu, Dec 20, 2012 at 2:57 AM, Bart Thate <feedbackflow@gmail.com> wrote:
> Hi All !
>
> Is is possible and if yes, is it more easily possible (i am thinking f_back
> maybe) to get the context of the caller when in a function ?
>
> Like to which variable name is this object assigned ?
>
> Or whatever of the callers context that might be of interest.
>
> I want in a function or method determine the context of my caller and adapt
> the functionality accordingly.

First off, please don't! Your code will be *extremely* confusing.

You can find out what function is calling you, eg by throwing an
exception and checking the traceback. My 3AM brain can't think of a
way to get the current thread's traceback without throwing, but there
may well be a way. (I also don't know of a way to get any other
thread's traceback, but that doesn't matter to this discussion.)

But finding out what variable name your return value is to be assigned
to isn't possible at all. For one thing, it might not be assigned
anywhere - it might be being ignored, or it might be used in some
other expression, or anything.

Usually, the best way to adapt to your caller's environment is to be
passed a parameter that specifies the change.

ChrisA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web