global name is not defined
Hi all,
I'm trying to use plot.savadatatxt to save some data.
here is the MWE:
#######
from yade import pack, plot, export
import math
O.bodies.
sp=pack.
sp.makeCloud(
sp.toSimulation()
O.engines=[
ForceResetter(),
InsertionSortC
InteractionLoop(
[Ig2_
[Ip2_
[Law2_
),
PyRunner(
PyRunner(
NewtonIntegrat
]
O.dt=.5*
print(len(
def checkUnbalanced():
if unbalancedForce
O.pause()
x0 = 0.5
y0 = 0.5
z0 = 0.5
#######
def subbox():
global ball_list1
ball_list1 =[]
global b_radius
b_radius = []
for b in O.bodies:
brp = math.sqrt(
if brp >= 0.2:
if brp <= 0.4:
if (b.state.pos[2]-z0 >= -0.5) and (b.state.pos[2]-z0 <= 0.0):
if isinstance(
b.shape.color =Vector3(
m = b.id
r = b.state.pos[0]
ball_
b_
ccc = sum(b_radius)
aaa= len(ball_list1)
plot.addData(
plot.saveDataT
O.run(1000000,True)
#######
If I just use this command :plot.saveDataT
but if I just want to save the bbb data, I change the command plot.saveDataTx
the error will be: NameError: global name 'bbb' is not defined
To my knowledge, I put the plot.savedatatxt command inside the function, why do we still need the global name?
Besides, I want to use the plot.savedatatxt to save some other information. so I made another MWE:
from yade import pack, plot, export
import math
O.bodies.
sp=pack.
sp.makeCloud(
sp.toSimulation()
O.engines=[
ForceResetter(),
InsertionSortC
InteractionLoop(
[Ig2_
[Ip2_
[Law2_
),
PyRunner(
PyRunner(
PyRunner(
NewtonIntegrat
]
O.dt=.5*
print(len(
def checkUnbalanced():
if unbalancedForce
O.pause()
x0 = 0.5
y0 = 0.5
z0 = 0.5
#######
def subbox():
global ball_list1
ball_list1 =[]
global aaa
global bbb
aaa = 0.0
bbb = 0.0
for b in O.bodies:
brp = math.sqrt(
if brp >= 0.2:
if brp <= 0.4:
if (b.state.pos[2]-z0 >= -0.5) and (b.state.pos[2]-z0 <= 0.0):
if isinstance(
b.shape.color =Vector3(
m = b.id
ball_
aaa= len(ball_list1)
def getdata():
plot.addData(
plot.saveDataT
O.run(1000000,True)
##############
for this code, even though, I set the global aaa, but i still got the error:
NameError: global name 'aaa' is not defined
##########
I don't know is this related to my misunderstanding of the global variable and local variable in python or something else?
thanks in advance.
best,
yong
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- Yade Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- Jan Stránský
- Solved:
- Last query:
- Last reply: