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

And then loop through a list to make the rest of the variables.


Popular posts from this blog

Communicating and downloading data from the James Webb Space Telescope

Python decorator: Example 1

Giving up on PDF annotations