Is this possible in Python? SOLUTION FOUND
Kay Schluehr
kay.schluehr at gmx.net
Tue Mar 14 13:15:16 EST 2006
alainpoint at yahoo.fr wrote:
> jalanb wrote:
> > You might like the version here:
> > http://www.jorendorff.com/toys/out.html
> >
> > Especially the "need to know" presentation, which is cute
> >
> > --
> > Alan
> > http://aivipi.blogspot.com
>
> Thank you for the tip.
> Meanwhile, I found a shorter solution to my problem:
> def magic(arg):
> import inspect
> return inspect.stack()[1][4][0].split("magic")[-1][1:-1]
>
> assert magic(3+4)=="3+4"
>
> Alain
Does it? Using your function I keep an assertion error. Storing the
return value of magic()in a variable s I receive the following result:
def magic(arg):
import inspect
return inspect.stack()[1][4][0].split("magic")[-1][1:-1]
s = magic(3+4) # magic line
>>> s
'lin'
BTW grepping the stack will likely cause context sensitive results.
Kay
More information about the Python-list
mailing list