Jeff Schwab <[EMAIL PROTECTED]> writes: > Jerry He wrote: >> Hi, suppose I have the following string >> cmdstr = "b = lambda s: s*s" >> Is there a way to execute this string other than >> copying it onto a file and then importing it? > > >>> exec "b = lambda s: s*s" > >>> b
Jeff forgot to warn you that exec is a *dangerous* function. Don't use it on data that you aren't 100% sure of the origin of. Better yet, avoid it if at all possible. If you'll tell us why you think you need to do this, possibly we can help you avoid using exec. <mike -- Mike Meyer <[EMAIL PROTECTED]> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list