Re: How to add function return value
- From: Raymond Hettinger <python@xxxxxxx>
- Date: Fri, 30 May 2008 19:16:08 -0700 (PDT)
On May 30, 6:21 pm, HYRY <ruoyu0...@xxxxxxxxx> wrote:
Can I write a decorator that it can automately do this conversion
def func1()
a = 1
--->
def func1():
a = 1
return locals()
Not sure why you would want to do this, but there are several ways.
1. Make bytecode hack decorator that transforms the final "return
None" into "return locals()". A recipe that shows the basic technique
is at: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/277940
2. Retrieve the source using inspect.getsourcelines(f). Then, append a
"return locals()" to the end of the function and run it through exec.
3. Try hacking a tracing/debugging utility.
4. Run the sourcefile through tokenize, make the appropriate
insertion, and then untokenize.
. . .
Raymond
.
- Follow-Ups:
- Re: How to add function return value
- From: George Sakkis
- Re: How to add function return value
- References:
- How to add function return value
- From: HYRY
- How to add function return value
- Prev by Date: Re: SMS sending and receiving from website?
- Next by Date: compatability
- Previous by thread: How to add function return value
- Next by thread: Re: How to add function return value
- Index(es):
Relevant Pages
|