Is there a way of executing a command in a string?

J

Jerry He

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?

thanks in advance,

Jerry

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
 
J

Jeff Schwab

Jerry said:
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?
<function <lambda> at 0x4d69cc>
 
M

Mike Meyer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top