I apologize if this is a bit basic, but I'm mostly a JavaScript developer so I'm unfamiliar with the way Python interprets code. It looks like I'm running into some sort of async/hoisting error on the following code:
if resultsLength == 10:
listLength = df.head(10).iterrows()
elif resultsLength == 15:
listLength = df.head(15).iterrows()
elif resultsLength == 20:
listLength = df.head(20).iterrows()
elif resultsLength == 25:
listLength = df.head(25).iterrows()
for index, row in listLength:
.../do stuff
The error I'm getting is this:
UnboundLocalError: local variable 'listLength' referenced before assignment
How do I deal with asynchronous issues like this in Python? Am I supposed to define the for loop as a function and use it as a callback?
solution:
Alex Hall was correct, my if test was failing because I forgot to convert resultsLength to an int, like so
if int(resultsLength) == 10:
For the record, I really shouldn't be getting downvotes for asking a "stupid" question if the majority of people are upvoting the wrong answer. Thanks, Alex, for correctly pointing out the issue.
for index, row in df.head(listLength).iterrows():