I'm trying to call variable from external file. And for that I wrote this code,
count = 1
while (count <= 3):
# I want to iterate this line
# rand_gen is the python file
# A is the varialbe in rand_gen.py
# Having this expression A = np.random.randint(1, 100)
from rand_gen import A
print('Random number is ' + str(A))
count = count + 1
But when I run my code it only calls varible A once and prints the same result. See the output of code,
Random number is 48
Random number is 48
Random number is 48
How can I call variable A from file rand_gen.py with updated value, every time it goes into loop? Please help.
Adoesn't change the value, it was assigned the first time you loaded the module. Why aren't you just callingnp.random.randint(1, 100). You can force it but it is very unintuitive, e.g.import importlib; importlib.reload(rand_gen)Aa function and call it, e.g.def A(): return np.random.randint(1, 100)thenstr(A())will give you a different value each time.