Dear Stan On Aug 25, 11:59 am, Stan Schymanski <[EMAIL PROTECTED]> wrote: > I wondered how python handles assigned variables in function > definitions.
As much as i understood a recent thread on sage-devel, several people would like to have a powerful substitution mechanism in Sage. Concerning your problem: In the definition of h, you use y.subs(locals()). But i think this can not work, because locals() refers to the current name space (or what is the word for it?). So, unless you define a and b *inside* the definition of h, it wouldn't work. However, you define a and b in the *global* name space. So, the following does work: sage: var('a b x') (a, b, x) sage: y=a*x^2+b*x sage: def h(x): ....: return y.subs(globals()) ....: sage: h(x) a*x^2 + b*x sage: a=2 sage: h(x) 2*x^2 + b*x sage: b=3 sage: h(x) 2*x^2 + 3*x Cheers Simon --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---