Question re: eval()

Emile van Sebille emile at fenx.com
Fri Dec 29 21:22:24 CET 2000


I'm still not following.  Will the user be typing in
something that needs specifically to be eval'd?  If so, eval
won't take a UserDict or class.  You may be able to populate
a dictionary by determining the variables in the expression
(see sample below).  Or will it be (or could it be) a
properly formed SQL statement?  Or will they be providing
parameters for information to be accessed, such as a
parameter names and range values?

#--- for simple expressions

def getEvalVars(s, sgVars=None, slVars=None):
    if sgVars == None:
        sgVars={}
    if slVars == None:
        slVars={}
    stillErrors = 1
    newVars = []
    while stillErrors:
        try:
            eval(s, sgVars, slVars)
            stillErrors = 0
        except NameError, err:
            stillErrors = 1
            errDesc = str(err)
            missingVar = errDesc.split("'")[-2]
            slVars[missingVar] = 1
            newVars.append(missingVar)
        except:
            stillErrors = 0
            pass
    return newVars

print getEvalVars('these + names + are + missing')


--

Emile van Sebille
emile at fenx.com
-------------------


"Clarence Gardner" <clarence at netlojix.com> wrote in message
news:978118012.3281608 at news.silcom.com...
> On Fri, 29 Dec 2000, Emile van Sebille wrote:
> >What are you trying to do that using a dict doesn't
address?
>
> The lazy evaluation.  Not only will the values that I want
to supply
> require large database accesses to retrieve, but I don't
even know
> with what names they will be requested!
>
> Clarence Gardner
> clarence at netlojix.com





More information about the Python-list mailing list