Using Python to read data and use it in an if statement -


i have python script writing .txt file (temperature in c). looking way read data , use in if statement.

the .txt file contains temp, ex. (20.0), , know how read data , print it, cant use data reason.

your problem expect 20.0 read file float. doesn't work way. when read file string, when say:

temp = my_data_read_from_file if temp >= 20.0:     print("hot") 

you're saying:

if '20.0' >= 20.0:     print("hot") 

strings , floats don't compare way. see mean try this:

>>> '0' > 10000 true 

you need cast file input float comparison:

temp = float(my_data_read_from_file) if temp >= 20.0:     print("hot") 

Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -