1

can anybody help me please to make sure the API_Duplicate outside of the while loops only runs once?

My methodology is:

for while MarketIsActive == 'True' to run continuously, listening for updates and assigning it to API_Data.

outside of the while loop, the API_duplicate = API_Data only needs to execute the once to assign its value.

this allows the second while loop, while API_Duplicate != API_Data to perform and take over the responsibility of assigning the API_duplicate = API_Data within the loop itself.

while MarketIsActive == 'True':
    API_data = 'API_endpoint'

API_duplicate = API_Data

    while API_Duplicate != API_Data
        API_duplicate = API_Data

        # extra code

Thank you.

4
  • your code has indentation errors Commented May 22, 2020 at 20:06
  • I wrote it like that because I didn't want the duplicate to update itself more than once, so I thought it would be best to exclude it from the first while loop Commented May 22, 2020 at 20:13
  • use if condition if API_Duplicate != API_Data Commented May 22, 2020 at 20:18
  • an if statement wouldn't execute because the "API_Duplicate" assignment is still executing before it? Commented May 22, 2020 at 21:25

1 Answer 1

1

Put your code inside a class, have the class have a count variable, and assign API_duplicate via a setter method, something like:

def set_dup(self):
    if self.count < 1:
        self.API_duplicate=self.API_data
        self.count +=1
Sign up to request clarification or add additional context in comments.

1 Comment

thank you for solving this issue, but the second while loop does not identify the API_duplicate.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.