[BangPypers] Executing a string
raj.amal at gmail.com
Wed Apr 23 12:39:31 CEST 2008
Try the Exec statement of python.
On Wed, Apr 23, 2008 at 4:03 PM, Heshan Suriyaarachchi <
heshan.suri at gmail.com> wrote:
> If I execute the following code I will get the the output as 2. What I
> need is to execute the string str. Is there a way that I can execute the
> string str as it is, so I will get the output as 5.
> def add(a,b):
> return a+b
> var = 2
> str = "var = add(2,3)"
> # execute the code snippet inside the str string variable
> print var
> Heshan Suriyaarachchi
> BangPypers mailing list
> BangPypers at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the BangPypers