python eval weirdness

Posted by amadain on Stack Overflow See other posts from Stack Overflow or by amadain
Published on 2010-04-29T10:17:19Z Indexed on 2010/04/29 10:27 UTC
Read the original article Hit count: 339

Filed under:
|

Hi Folks I have the following code in one of my classes along with checks when the code does not eval:

filterParam="self.recipientMSISDN==tmpBPSS.split('_')[3].split('#')[0] and   self.recipientIMSI==tmpBPSS.split('_')[3].split('#')[1]" 
if eval(filterParam):
   print "Evalled"
else:
   print "Not Evalled\nfilterParam\n'%s'\ntmpBPSS\n'%s'\nself.recipientMSISDN\n'%s'\nself.recipientIMSI\n'%s'" % (filterParam, tmpBPSS, self.recipientMSISDN, self.recipientIMSI)

I am not getting anything to 'eval'. Here are the results:

Not Evalled
filterParam
'self.recipientMSISDN==tmpBPSS.split('_')[3].split('#')[0] and    self.recipientIMSI==tmpBPSS.split('_')[3].split('#')[1]'
tmpBPSS
'bprm_DAILY_MO_919844000039#892000000'
self.recipientMSISDN
'919844000039'
self.recipientIMSI
'892000000'

So I used the outputs from the above to check the code in a python shell and as you can see the code evalled correctly:

>>> filterParam="recipientMSISDN==tmpBPSS.split('_')[3].split('#')[0] and recipientIMSI==tmpBPSS.split('_')[3].split('#')[1]"
>>> tmpBPSS='bprm_DAILY_MO_919844000039#892000000'
>>> recipientMSISDN='919844000039'
>>> recipientIMSI='892000000'
>>> if eval(filterParam):
...    print "Evalled"
... else:
...    print "Not Evalled"
...
Evalled

Am I off my rocker or what am I missing?

A

© Stack Overflow or respective owner

Related posts about python

Related posts about eval