python beginner here. My file contains lines that consists of conditions that are formatted just like a python if statement (without the if in the beginning and colon in the end). Example:
temperature < 40 and weekday == "Thursday" and (country != "Norway" or country != "USA")
(temperature != 30 or temperature != 35) and weekday == "Friday" and country == "Canada"
I want to write code that reads the lines as if they were if statements and prints True or False depending on if the conditions were met. I am thinking something along the lines of:
temperature = 35
country = "Canada"
weekday = "Friday"
file = open('output.txt', r)
lines = file.readlines()
for line in lines:
if line:
# if conditions in string are met, print true
print(True)
else:
# else print False
print(False)
which should when run with above file lines should output
False
True
EDIT:
Would it be possible to reliably and consistently parse the file lines and process it, like how I'm assuming a python compiler would read an actual if statement?