Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

evaluating a string with variable assignments

Suppose I have a long string of Sage code that performs some variable assignment. I'd like to evaluate it so that those variables become defined in the Sage session. For the sake of simplicity, let it be:

cmd = 'a=1;b=2;'
sage_eval('None',cmds=cmd)
print(a)

This particular code evaluates cmd successfully but the variable values are lost upon completion of sage_eval, which is not what I want. Is it possible to evaluate cmd with keeping all variables assigned?

PS. I know a workaround with a,b = sage_eval('a,b',cmds=cmd) but I'd like avoid explicit communicating of variable values.

evaluating a string with variable assignments

Suppose I have a long string of Sage code that performs some variable assignment. I'd like to evaluate it so that those variables become defined in the Sage session. For the sake of simplicity, let it be:

cmd = 'a=1;b=2;'
sage_eval('None',cmds=cmd)
print(a)

This particular code evaluates cmd successfully but the variable values are lost upon completion of sage_eval, which is not what I want. Is it possible to evaluate cmd with keeping all variables assigned?

PS. I know a workaround with a,b = sage_eval('a,b',cmds=cmd) but I'd like to avoid explicit communicating communication of variable values.