making a global module python code example
Example 1: global python
"""
USING GLOBALS ARE A BAD IDEA, THE BEST WAY TO PERFORM AN ACTION WHICH NEEDS GLOBALS WOULD
BE TO USE RETURN STATEMENTS. GLOBALS SHOULD ONLY EVER BE USED IN RARE OCCASIONS WHEN YOU
NEED THEM
"""
EXAMPLE:
def test_function():
global x
x = 10
test_function()
print(f"x is equal to {x}")
Example 2: python global import
>>> math
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'math' is not defined
>>> def f():
... global math
... import math
...
>>> f()
>>> math
<module 'math' from '/usr/local/lib/python2.6/lib-dynload/math.so'>