@lawrenceyy wrote:
I've gotten my fair share of the error: var referenced before assignment, so I wanted to know what is the best way to deal with global and local variables as well as when and when not to use arguments. FYI, I use GhPython for the most part.
Are variables initiated outside functions automatically global variables? I don't have an example right now, but I've found myself in situations where the "referenced before assignment" error is given when I have a function that references global variables (these global variables are often defined at the bottom of the script just before all the functions are executed). This however is often fixed when I pass that variable through as an argument and overwrite the original global with the returned value.
Am I always supposed to provide arguments? I prefer not having so many variations of the same variable name, especially when I have functions in functions that use the same variables. In the case of functions in functions, can/should an argument have the same name as the local variable you are passing through (to avoid having so many variable names)?
The reason why I am interested in using global variables is that it makes using ghpythonlib.parallel() easier when you have may lists. If we don't use global variables, how do we pass through multiple lists (like a list of curves you want to project onto a list of surfaces)?
Posts: 7
Participants: 6