The question is vague because the problem is to abuse Python for a good cause.
Suppose i have python as program input:
scf() # produces F,C that are somehow available globally
ci() # uses F,C
question is, can scf modify the module of the caller?
and second case:
F,C = scf() # F,C are not set globally.
So basically either capture value (x)or set it globally.
How can it be done?
It makes me ill to share this, but in CPython you can alter the stack frame:
However, why do you need to invisibly alter the namespace of the caller? This reeks of bad design.
scf()should return things andci()should accept those things as arguments. If you share more about what you are doing perhaps we can suggest better approaches.Update
So you’re trying to maintain some state between externally-executed strings which are Python programs. This is trivial to do in Python: simply keep an explicit locals and globals namespace and pass it between invocations of
execand friends.Perhaps to keep some semblance of sanity you can guarantee to your users that one special var will be persisted between runs: