Instead of writing long 'if' statement, I would like to store that in some variable then pass it into 'if' condition. For example:
tempvar = '1 >0 and 10 > 12'
if tempvar:
print something
else:
do something
Does it possible in python ?
Thanks for your suggestion but my problem is something else which I can't figure out. I am doing multi string search in text file and trying to convert multi string into one condition:
allspeciesfileter=['Homo sapiens', 'Mus musculus', 'Rattus norvegicus' ,'Sus scrofa']
multiequerylist=[]
if len(userprotein)> 0:
multiequerylist.append("(str("+ "'"+userprotein+ "'"+")).lower() in (info[2].strip()).lower()")
if len(useruniprotkb) >0:
multiequerylist.append("(str("+ "'"+useruniprotkb+ "'"+")).lower() in (info[3].strip()).lower()")
if len(userpepid) >0:
multiequerylist.append("(str("+ "'"+userpepid+ "'"+")).lower() in (info[0].strip()).lower()")
if len(userpepseq) >0:
multiequerylist.append("(str("+ "'"+userpepseq+ "'"+")).lower() in (info[1].strip()).lower()")
multiequery =' and '.join(multiequerylist)
for line in pepfile:
data=line.strip()
info= data.split('\t')
tempvar = bool (multiquery)
if tempvar:
do something
But that multiquery is not working
(1 > 0) and (10 > 12)is a boolean value, so just store that in a variable. I.e. you're almost there, just don't turn the expression into a string (for whatever reason you did that).