[SciPy-dev] How to get extensions to affect local state
Pearu Peterson
pearu at cens.ioc.ee
Mon Feb 11 17:45:39 EST 2002
On Mon, 11 Feb 2002, eric wrote:
> This will only work in certain situations and is not guaranteed to work in
> the future. Here is an example where it doesn't work:
>
> def bob(var):
> frame = sys._getframe(1)
> exec '%s = 7' % (var,) in frame.f_locals
>
> So it works when called from the module level, but not when called from
> within a function. Also this approach is extremely slow compared to doing
> within the C function, so you'd loose much of the benefit of the things
> weave and PyCOD are trying to do.
You are right. Doing
exec '%s = 7' % (var,) in frame.f_locals
is actually equivalent to
exec '%s = 7' % (var,) in locals()
just in one level up and your example demonstrates that the warning about
locals() in Python docs is real.
PS: I also second Pauls and Fernandos concerns about algorithms flow into
scipy. Scipy should provide only the best and throw out all the second
best ones (and only if they are proved to be so in all aspects) in order
to reduce the code base and increase scipy maintainability. Pauls
suggestion about OOP approach would also ease this selection of
algorithms.
Regards,
Pearu
More information about the SciPy-Dev
mailing list