[BangPypers] Executing a string

Heshan Suriyaarachchi heshan.suri at gmail.com
Wed Apr 23 12:33:04 CEST 2008

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/bangpypers/attachments/20080423/c1554fc4/attachment.htm>

More information about the BangPypers mailing list