I have two functions:
def read_temp():
lines1, lines2 = read_temp_raw()
while lines1[0].strip()[-3:] != "YES":
time.sleep(0.2)
lines1, lines2 = read_temp_raw()
temp1 = calculate_temp(lines1)
temp2 = calculate_temp(lines2)
return temp1, temp2
def Temp_difference():
if temp1 > temp2:
print(temp1 - temp2)
else:
print(temp2 - temp1)
I want to use temp1
and temp2
in Temp_difference
. When I try adding the variables globally in read_temp
, my IDE (Pycharm) says: "Global variable 'temp1/2' is undefined at the module level". I've tried to do it this way:
def Temp_difference(temp1, temp2):
print (abs(temp1-temp2))
I'm not getting any warnings or errors here, but I don't know if that is correct. So is there a better/correct way to do this?