Python Forum

Full Version: Not sure how to turn this into a loop
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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.