quick eval question

craig curtin curtin at ubsw.com
Sun Dec 16 07:49:16 EST 2001


very sad when u follow up on your own posts 3x ;-)

well, anyways here is what i learned.

when u eval() you must evaluate an entire left hand side.
exec() is used for executing a statement within the context
of the current interpreter.

i was trying to eval just the index part of the below statement

ePath ="elements['OUTLOOK']['CREATEDATE']"
eEval = "elements['OUTLOOK']['CREATEDATE'] = '12/10/01 17:21:23'"
exec(eEval)
and 
eval(ePath)

> elements = {}
> elements['OUTLOOK'] = {}
> elements['OUTLOOK']['CATEGORY'] = 'DEVL_TEST'
> elements['OUTLOOK']['AUTHOR'] = {}
> elements['OUTLOOK']['AUTHOR']['ADDRESS'] = 'John Smith/Devl'
> elements['OUTLOOK']['AUTHOR']['NAME'] = 'Engineering Division'
> elements['OUTLOOK']['AUTHOR']['TYPE'] = 'SMTP'
> elements['OUTLOOK']['CREATEDATE'] = '12/10/01 17:21:23'
> 
> # now i want a 'path component'
> ePath ="['OUTLOOK']['CREATEDATE']"
> 
> # i can't seem to put the dict and path together
> print elements+ePath
> #print elements eval(ePath)
> 
> #print eval(elements eval(ePath))
> 
> hope this makes sense,
> 
> craig
> 
> curtin at ubsw.com (craig curtin) wrote in message 
> > i'm looking to do something like this but my brain is failing...
> > 
> > i = [1,2,3,4,5]
> > j = '[2]'
> > 
> > k = eval( i j )
> > 
> > ie. i want to get k = 3 ...



More information about the Python-list mailing list