Bill Allombert on Thu, 22 Oct 2015 14:54:02 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: eval of numeric strings |
On Thu, Oct 22, 2015 at 02:39:08PM +0200, Josef Eschgfaeller wrote: > I would like to define a function evaln > which evaluates a string to a number > only if the string contains explicitly > the decimal representation of that > number, not a variable. > -------------------------------------------------- > Behavior of eval: > > x=17; > s=eval("x"); print(s); \\ 17. > t=eval("17"); print(t); \\ 17. > y="John" > r=eval("y"); print(r); \\ John > -------------------------------------------------- > Desired behavior of evaln: > > x=17; > s=evaln("x"); print(s); \\ x. > t=evaln("17"); print(t); \\ 17. > y="John" > r=evaln("y"); print(r); \\ y. What should give: evaln("x2") evaln("2x") Cheers, Bill.