yade-users team mailing list archive
-
yade-users team
-
Mailing list archive
-
Message #13871
Re: [Question #407567]: the global cannot work
Question #407567 on Yade changed:
https://answers.launchpad.net/yade/+question/407567
Status: Open => Answered
Klaus Thoeni proposed the following answer:
Hi,
not sure what you are trying to do with the second line but this should
work:
x = 1
y = 1
print x # gives 1
print y # gives 1
def func():
global x # here you define that x is global, hence you can change it inside the function
x = 2
y = 2 # Python assumes that any name that is assigned to, anywhere within a function, is local to that function unless explicitly told otherwise
func()
print x # gives 2
print y # gives 1
Also, in order to be sure you get the right answer you want your last
print outside the function.
Finally, this is not a YADE specific question, hence, next time please
look at the python documentation.
Klaus
--
You received this question notification because your team yade-users is
an answer contact for Yade.