I have a python script which defines a couple of objects like this
# A.py
a - some dict
b - some dict
c - some dict
d - some dict
Now, I have another script B.py in which I want to access a,b,c,d but it based on some variable, I would select which of those to use
# By.py
import A as A_objects
input = 'a'
# Since the input is 'a' here, I want to call A_objects.a.value
print(A_objects.input.value) # Does not work
Here is the error:
AttributeError: module 'A' has no attribute 'input'
This sounds like a basic problem to me but I am unable to find a solution. One approach which I have in mind is to create a dictionary with string and objects like
global_dict = { 'a': a, 'b': b ... }
And get objects/dicts as global_dict.get(input) in B.py
Let me know what is the best practice of achieving this use case.
inputis the name of a built-in function, so you should avoid defining variables with the same name because then the Python provided one can no longer be used.