[BangPypers] Executing a string

Amal raj.amal at gmail.com
Wed Apr 23 12:39:31 CEST 2008


Try the Exec statement of python.

Amal.

On Wed, Apr 23, 2008 at 4:03 PM, Heshan Suriyaarachchi <
heshan.suri at gmail.com> wrote:

> Hi,
> 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
>
> --
> Regards,
> Heshan Suriyaarachchi
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>
>


-- 
Amal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/bangpypers/attachments/20080423/c9e3796f/attachment.htm>


More information about the BangPypers mailing list