← Back to team overview

yade-users team mailing list archive

Re: [Question #685061]: global name is not defined

 

Question #685061 on Yade changed:
https://answers.launchpad.net/yade/+question/685061

    Status: Open => Answered

Jan Stránský proposed the following answer:
Hello,

a quick solution:
Note that vars in plot.saveDataTxt is "Sequence (tuple/list/set) of variable names to be saved" [1], so use something like:
###
from yade import plot
plot.addData(bbb=1,aaa=2,ccc=3)
plot.addData(bbb=4,aaa=5,ccc=6)
plot.saveDataTxt("testAll.dat")
plot.saveDataTxt("testaaabbb.dat",vars=["aaa","bbb"])
plot.saveDataTxt("testaaa.dat",vars=["aaa"])
###

> I don't know is this related to my misunderstanding of the global
variable and local variable in python

most likely.
a good solution is not to modify global variables :-)

For the first code:
> plot.addData(bbb=aaa )
bbb is just a parameter name of plot.addData function, not even a variable. 
> plot.saveDataTxt('ball-number.txt',vars=(bbb))
here Python is lost, because it does not know anything about bbb..
A variable becomes variable after assignment "="

Second code:
First time you declare aaa in subbox (iterPeriod=1000), before Python knows nothing about aaa.
But you require it in getdata (iterPeriod=100), which is called prior to subbox and, as Python says, aaa is not defined.

also please try to make your MWE really MWE, where M stands for minimal [2].
As you add some toy data anyway, packing, checkUnbalanced, most engines, most of subbox function etc. are not related to the problem at all and could be excluded..

cheers
Jan

[1] https://yade-dem.org/doc/yade.plot.html#yade.plot.saveDataTxt
[2] https://www.yade-dem.org/wiki/Howtoask

-- 
You received this question notification because your team yade-users is
an answer contact for Yade.