What I am trying to is pretty basic. Inside an elif statement, I am trying to open a .txt file get the text from it and compare the text and accordingly execute if and elif statements. However, the issue I am facing is the if and elif statements are not getting executed. Below is my code:
def readData(id):
command_received = str(id)
if command_received in ("A1","A2"):
file1 = open("Status.txt","r+")
mstatus = file1.read()
print(mstatus)
if mstatus == "Busy":
f1.close()
print("Busy")
elif mstatus == "Ready":
file1.write("Busy")
file1.close()
#Rest of the code follows here#
else:
print("Something is wrong")
This is the output that am getting:
Ready
Something is Wrong
The if and elif statements under the elif statements are not getting executed and only the else statement is getting printed. The text stored in the txt file is "Ready". Also the txt file and the py script are in the same location. Thanks for your time and help in advance.
Aucun commentaire:
Enregistrer un commentaire