Python Boolean Logic

Bill BILL_NOSPAM at whoknows.net
Sat Sep 23 03:08:45 EDT 2017


Steve D'Aprano wrote:
> On Sat, 23 Sep 2017 03:01 pm, Bill wrote:
>
>> s='(20 - 10)  > 15'
>> b=(20 - 10)  > 15
>> print(s, " is ", ("true" if b else "false") );  ## inside parentheses
>> may be removed.
>>
>> I am new to Python.  Maybe someone here is familiar with an elegant way
>> to get the the value of b directly from the string s?  Hmm... It appears
>> that eval() would work
>
> Indeed it will, but don't get into the habit of using eval willy-nilly. While it
> is absolutely fine to use it with data you provide yourself, it is a HUGE
> security risk to eval strings that came from an untrusted user.
>
>
> eval("__import__('os').system('echo """rm-rf /"""')")

Thank you. Studying that was a nice little lesson in itself!   I 
recognize that this technique can be used for 'good' as well as 'evil'!  : )

Bill




More information about the Python-list mailing list