(Jan-11-2017, 06:51 PM)snippsat Wrote: Do not use global
You give argument to function and return value out.
Well that's a way, but some functions has a lots of arguments.
Using global I can simplify my code and avoid atributions errors.
(Jan-11-2017, 07:40 PM)micseydel Wrote: I don't quite understand the question. Can you show the problem(s) that arise from not being able to do what you want to?
Ok, I wrote this simple code to illustrate the problem.
Here's my main file:
#!/usr/bin/env python3 import numpy as np from function import fwd global I I = 90 result = fwd() print(result)My function "fwd" are in another file. This is the function code:
#!/usr/bin/env python3 def fwd(): global I J = 10 K = I + J return [K]When I try to run I receive this error:
Error:" NameError: name 'I' is not defined "
Basically, I want my program to call different functions, that can use the globals to do the math which I need to calculate different physics properties. Thanks for the help.