0

So I am writing a script to retrieve dataframes from an API and have a large list to do this for and would like to iterate over them to request it for each.

I have seen that this would possibly solve my problem:

for x in list:
    globals()['string%s' % x] = dataframe #code to go get the dataframe

however this is deemed bad practice. Hoping someone could clarify why and if this use case warrants it?

T. Hinde
  • 11
  • 5
  • 1
    At best, you are just replacing something like `strings[3]` with `string3`. At worse, you don't know how many `stringx` variables you have, whereas you can always call `len(strings)` to find out how many such things there are. – chepner Apr 02 '20 at 13:27
  • The list of data frames being pulled is closely monitored so the length wouldn't be an issue. However I've figured a work around with dictionaries, it's a little safer as you say. – T. Hinde Apr 05 '20 at 13:45

0 Answers0