+ 3
Why is there an error for z
6 Réponses
+ 7
Oma Falk In theory, you would want to say globals = locals, rather than the other way around as you want to change the globals dict.
You can use globals().update(locals()) instead though.
+ 8
z is created in the function, so it is not accessible in the scope of main program. To avoid this, create z at the place where x and y are created, or use global.
x=8
y=10
def myadd():
global z
z=44
return x+y
print(myadd())
print(z)
+ 4
Oma Falk Well I've never been called that before! Yeah, the normal way of doing things is to say global z as other have pointed out.
+ 2
Russ you are a woman whisperer!
That's it.
(Although I would not survive the day on which I deliver this kind of code to my chief)
0
i hoped, locals=globals
will do it.