I have a question which is more about a general understanding of loops and case-structures. Therefor I will not deliver a runable code.
Is there somehow an option to iterate over objects of a function? I use a if-elif differentiation to call diffent files of a dataset.
Is it possible for the user of this function to make a request about all possible cases the programmer/data base manager offers in this function?
I try to better explain my question in an example:
Example of available datasets given in a if-else-structure (the user might not be aware of all possible choices that can be called):
def data(date):
if date == '20220318':
file = 'dataset_a'
return file
elif date == '20220317':
file = 'dataset_b'
return file
elif date == '20210712':
file = 'dataset_c'
return file
elif date == '20210708':
file = 'dataset_d'
return file
elif date == '20210621':
file = 'dataset_e'
return file
else:
raise Exception("Invalid date")
The result I am aiming at is a list of all "date"-objects like:
20220318
20220317
20210712
20210708
20210621
A direct iteration seems not to be possible like:
for date in data:
print(date)
This leads to TypeError: 'function' object is not iterable. Is there a way to call all possible choises?
Thanks for helping to understand how loops really work.