globals() and creating 100 global variables at once
Ran into this scenario where I had to make 100 global variables programmatically. For example, x0 = 0, x1 =1, x2= 2 and so on till x100 = 100.
One way to do this in python using `globals()`
Example :
>>> globals()['x0'] = 0
>>> x0
0
And then loop through a list to make the rest of the variables.
Comments
Post a Comment