Is it possible to define a global variable inside a function? like this:
def posities():
global blauw
blauw = {"bl1":[0], "bl2":[0],"bl3":[0],"bl4":[0]}
global geel
geel = {"ge1":[0], "ge2":[0],"ge3":[0],"ge4":[0]}
global groen
groen = {"gr1":[0], "gr2":[0],"gr3":[0],"gr4":[0]}
global rood
rood = {"ro1":[0], "ro2":[0],"ro3":[0],"ro4":[0]}
global ingenomenPos
ingenomenPos = []
Or MUST I first declare to the variables outside of the function? Because when I define them inside the function and I try to acces them from another function, it doesn't recognise it. So I want to declare global variables without first declaring them outside the function.
So I try to acces those globals with this method:
def bezet():
print (str(ingenomenPos))
which results in the error:
NameError: name 'ingenomenPos' is not defined
globaldeclarations just above each definition, you can do them all at the top like this:global blauw, geel, groen, rood, ingenomenPos