May-20-2022, 05:23 PM
Hi all,
I've run up against this issue a number of times so I thought I'd seek advice on the best way to handle it.
Suppose I have a large data file and I don't know how often a pattern will repeat. Each time it occurs, though, I need to capture details and later evaluate to select which one I'll need.
What is the best way to name variables in this case?
One approach would be to define as many or more sets than I'll ever need. For example:
I'd rather define and initialize the variables with a loop like:
This doesn't work:
Any general thoughts for something like this?
I've run up against this issue a number of times so I thought I'd seek advice on the best way to handle it.
Suppose I have a large data file and I don't know how often a pattern will repeat. Each time it occurs, though, I need to capture details and later evaluate to select which one I'll need.
What is the best way to name variables in this case?
One approach would be to define as many or more sets than I'll ever need. For example:
dte0 = dte1 = dte2 = dte3 = ... = dte50 = 0 row_num1 = row_num2 = row_num3 = ... = row_num50 = 0That seems like a pain.
I'd rather define and initialize the variables with a loop like:
variable_set = ['dte'+ str(i) for i in range(50)] print(variable_set)Now I've got the variable names in a list... could I then initialize them as a loop?
This doesn't work:
for i in len(variable_set): int(variable_set[i]) = 0 print(variable_set)Even if that did work, I think I might have just changed the list to all zeros, which loses the variable names for later use in the program. I don't know how to keep the strings as variable names for later use...
Any general thoughts for something like this?