Re: context aware execution

Discussion in 'Python' started by Chris Angelico, Dec 19, 2012.

  1. On Thu, Dec 20, 2012 at 2:57 AM, Bart Thate <> 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
     
    Chris Angelico, Dec 19, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    9
    Views:
    732
    Gabriel Genellina
    Nov 14, 2007
  2. Bart Thate

    context aware execution

    Bart Thate, Dec 19, 2012, in forum: Python
    Replies:
    0
    Views:
    129
    Bart Thate
    Dec 19, 2012
  3. Wayne Werner

    Re: context aware execution

    Wayne Werner, Dec 19, 2012, in forum: Python
    Replies:
    0
    Views:
    125
    Wayne Werner
    Dec 19, 2012
  4. Bart Thate

    Re: context aware execution

    Bart Thate, Dec 19, 2012, in forum: Python
    Replies:
    0
    Views:
    104
    Bart Thate
    Dec 19, 2012
  5. Michael Torrie

    Re: context aware execution

    Michael Torrie, Dec 20, 2012, in forum: Python
    Replies:
    0
    Views:
    127
    Michael Torrie
    Dec 20, 2012
Loading...

Share This Page