Hi, I’m trying to understand how global and local variable works INSIDE RHINOCEROS…
If I declare a variable outside (srfext and srfint) when I call it in Inverti function I got error (and crash of rhinoceros V5).
I tried to write global before but again I got error…
So, as global variable are foundamentals, can please someone explain me how to use it in Rhinoceros?
Are your functions class methods?
If so, you need to “declare” your global variables srfext and srfint as global inside the class or relevant class method, where you want to use them.
srfext = ""
srfint = ""
class Foo:
def inverti(self, sender, args):
global srfext, srfint
print srfext, srfint
@diff-arch no is not a class… But declaring global srfext, srfint inside the function worked!
Thank you so much!
So, to sum up:
srfext = ""
srfint = ""
def SrfSel(self,sender,args):
global srfext,srfint #THIS MUST BE WRITTEN IN ANY FUNCTION THAT USE GLOBAL VARIABLES
srfext = "Example"
srfint = "Example1"
def Inverti(self,sender,args):
global srfext,srfint #THIS MUST BE WRITTEN IN ANY FUNCTION THAT USE GLOBAL VARIABLES
print(srfint)
print(srfext)
What if you remove or rename the self parameter for each function?
It’s a default keyword reserved for class instances in Python and thus shouldn’t be used as symbol name otherwise! Maybe you using it, messes something up.