> I think that Your trace_returns function is actually a global trace
> that returns itself and does not handle the 'call' event.
By returning itself, the global trace also becomes the local trace.
The code in bdb.py does the same thing--- self.trace_dispatch is set
as the global trace, and retur
On 25 Apr 2005 23:31:29 -0700, "George Sakkis" <[EMAIL PROTECTED]> wrote:
>> I'm not clear on what your real goal is, but if you just want a
>snapshot
>> of what locals() is just before exiting func, that could be done with
>> a byte-code-hacking decorator with usage looking something like
>>
>>
George Sakkis wrote:
> That's all good, at least if I knew how to poke with bytecodes ;-)
> What's a good starting point to look at ?
http://sourceforge.net/projects/bytecodehacks/
http://bytecodehacks.sourceforge.net/bch-docs/bch/
For more recent development this ANN of Christian Tismer is imp
George Sakkis wrote:
> > Oh, I overlooked this. Then the solution becomes simple:
> >
> >sys._getframe().f_trace
> >
> > Test:
> >
> > >>> an = Analyzer()
> > >>> sys.settrace(an.trace_returns)
> > >>> sys._getframe().f_trace
> > at
> > 0x010015D0>>
>
> Does this work for you non-interactivel
> I'm not clear on what your real goal is, but if you just want a
snapshot
> of what locals() is just before exiting func, that could be done with
> a byte-code-hacking decorator with usage looking something like
>
> #func defined before this
> func_locals = {}
> @getlocals(func, func_l
> Oh, I overlooked this. Then the solution becomes simple:
>
>sys._getframe().f_trace
>
> Test:
>
> >>> an = Analyzer()
> >>> sys.settrace(an.trace_returns)
> >>> sys._getframe().f_trace
> 0x010015D0>>
Does this work for you non-interactively ? I tried running it from a
script or importing it
On 25 Apr 2005 03:32:38 -0700, "George Sakkis" <[EMAIL PROTECTED]> wrote:
>Is there a general way of injecting code into a function, typically
>before and/or after the existing code ? I know that for most purposes,
>an OO solution, such as the template pattern, is a cle
Lonnie Princehouse wrote:
> I don't know of a way to get the current global trace function. This
> could certainly cause trouble if you're trying to be compatible with
> other packages that want to use their own trace functions (like
psyco,
> or debuggers). Does anyone know how to get the globa
I don't know of a way to get the current global trace function. This
could certainly cause trouble if you're trying to be compatible with
other packages that want to use their own trace functions (like psyco,
or debuggers). Does anyone know how to get the global trace?
On the other hand, the lo
George Sakkis wrote:
> Thanks, that's the closest to what I wanted. A minor point I didn't
> quite get from the documentation is how to set a local trace instead
of
> a global (sys) trace.
You never do. "Local" in this context only means that those local trace
functions are called inside the one
"Lonnie Princehouse" wrote:
> I expect you could combine the following with decorators as an easy
way
> to grab a function's locals just before it exits... you could also
use
> exec or eval to execute code in the function's local namespace.
> ---
>
> # Try it:
I expect you could combine the following with decorators as an easy way
to grab a function's locals just before it exits... you could also use
exec or eval to execute code in the function's local namespace.
---
# Try it:
def trace_returns(frame, event, arg):
George Sakkis wrote:
Is there a general way of injecting code into a function, typically
before and/or after the existing code ? I know that for most purposes,
an OO solution, such as the template pattern, is a cleaner way to get
the same effect, but it's not always applicable (e.g. if you ha
Try searching for: 'python aspect-oriented' as aspect oriented
programming is about modifying existing class-methods (not exactly
functions which is what you asked for).
You might also do a search for "AOP considered harmful"
http://www.infosun.fmi.uni-passau.de/st/papers/EIWAS04/stoerzer04aop_harm
George Sakkis wrote:
Is there a general way of injecting code into a function, typically
before and/or after the existing code ? I know that for most purposes,
an OO solution, such as the template pattern, is a cleaner way to get
the same effect, but it's not always applicable (e.g. if you ha
Perhalps metaclasses are of interest to you. You can decorate existing
methods with additional behavior using metaclasses. A simple example
can be found at http://soiland.no/software/logmeta
I've gathered some more links under
http://www.gungfu.de/facts/wiki/field.php?pagename=Main.MetaProgramming
use eval.
eval will accept any string and treat the string as a code.
pujo
--
http://mail.python.org/mailman/listinfo/python-list
Is there a general way of injecting code into a function, typically
before and/or after the existing code ? I know that for most purposes,
an OO solution, such as the template pattern, is a cleaner way to get
the same effect, but it's not always applicable (e.g. if you have no
control ove
18 matches
Mail list logo