Jan-11-2017, 10:45 PM
#!/usr/bin/env python3 import numpy as np from function import fwd global I # Make no sense since I is in global namespace I = 90 # Is global result = fwd() print(result)Here how you do it.
#bar.py import numpy as np from foo import fwd I = 90 result = fwd(I) print(result)
#foo.py def fwd(I): J = 10 K = I + J return [K] if __name__ == '__main__': # Test this will not run on import I = 90 print(fwd(I))Running
bar.py
:λ python bar.py [100]
Quote:Using global I can simplify my code and avoid atributions errors.No,that not an excuse at all for using stupid global.
global destroy the whole point of functions,
which is keeping code local to function and not mix in with stuff in global namespace.
If it to difficult with function,using class is the next step.