Python Forum
Not sure how to turn this into a loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not sure how to turn this into a loop
#1
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
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Turn coordinates in string into a tuple Kolterdyx 3 2,696 Jun-10-2020, 05:04 AM
Last Post: buran
  How do i turn my program into a .exe julio2000 1 1,848 Feb-14-2020, 08:18 PM
Last Post: snippsat
  Do break operators turn while loop conditions from True to False? Drone4four 5 2,895 Oct-24-2019, 07:11 PM
Last Post: newbieAuggie2019
  How do I turn a directory of HTML files into one CSV? glittergirl 2 1,748 Sep-21-2019, 05:33 PM
Last Post: glittergirl
  Turn py into exe tester21 4 2,982 Jul-22-2019, 04:31 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020