[Tutor] eval use (directly by interpreter vs with in a script)

Alex Kleider akleider at sonic.net
Mon Nov 3 01:13:35 CET 2014

On 2014-11-02 13:49, Danny Yoo wrote:

> Are you just exploring the features of Python, or is there a
> particular task you're trying to solve with eval or exec()?  Perhaps
> you can accomplish the same goal in another way?

Thank you and also Peter for your help.

The answer to your question is "'yes' and 'no".
Having been watching this list for a long time I've certainly been aware 
that use of eval() is discouraged and I understand the reason for this.
My reason for using it is to develop a script that calculates the per 
person cost of a trip a group of 8 of us are planning.  The calculations 
are a bit complicated and based on a bunch of inter-related assumptions 
that may change so I wanted the assumptions to be in a separate string 
(called "assumptions") that can be modified as new information comes in. 
  I don't have to feed the assumptions as a string into an eval() but 
chose to do so just as an experiment. Because of the problems I've 
encountered (with naming scope,) I'll accomplish my goal in the standard 
way of simply making the assignments (that were in "assumptions") as 
inline code.


More information about the Tutor mailing list