[Tutor] Input to python executable code and design question

Ismael Garrido ismaelgf at adinet.com.uy
Sun Jan 9 23:33:34 CET 2005


Hello

I am trying to make a program that will plot functions. For that, I need 
to be able to get an input (the function to be plotted) and execute it. 
So, my question is, how do I use the input? I have found no way to 
convert the string to some kind of executable code.

I did research the problem. And found two things, first, an 
unsatisfactory solution from: 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52217
The code there, by means I cannot understand at all, executes a string 
as code. To be usable I have to make my code a huge string. It is not 
very elegant.

The second possible solution I found was using eval, compile and/or 
exec. But I do not understand what do they do, or how to use them, for 
the matter.

Related to the program I intend to do, which design would you say is 
more intelligent: one that first calculates the whole function, stores 
it, and then plots it; or one that calculates-plots-calc.-plot, and so on?

Thanks for any information, and for your time.
Ismael


More information about the Tutor mailing list