Not sure how to turn this into a loop - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Not sure how to turn this into a loop (/thread-14547.html) |
Not sure how to turn this into a loop - iamgonge - Dec-05-2018 Im very new to python and am a bit stuck. I have some code. I have a variable called data that is json that I need to access. The problem is I get the json but it has values that end up changing due to the system processing payment information. I need to access the json after its been updated. Id like to run a loop that checks that variable. code: data = json.loads(self.rfile.read( length ).decode('utf-8')) order_status = data['order_status']['name'] if not order_status == "Awaiting Payment": data = json.loads(self.rfile.read( length ).decode('utf-8')) I want a loop that keeps checking order_status-> name and once its no longer saying "Awaiting Payment" set the data variable Im not really sure how to do that RE: Not sure how to turn this into a loop - anandoracledba - Dec-05-2018 Try this... while True: data = json.loads(self.rfile.read( length ).decode('utf-8')) order_status = data['order_status']['name'] if not order_status == "Awaiting Payment": << further code >>Line indentation is very important in Python. |