← Back to team overview

yade-users team mailing list archive

[Question #406775]: about the local variable

 

New question #406775 on Yade:
https://answers.launchpad.net/yade/+question/406775

I am trying to make a simulation,and in the script I use PyRunner.
the PyRunner is like this:
--------------
jsdr=1546.6/1000
dct=radians(90-27)
globals()['dct']=locals()['dct']

sctt=[]
globals()['sctt']=locals()['sctt']
tjii1=[]
globals()['tjii1']=locals()['tjii1']
tjii1=tji1  #"tji1" is already known before and it is a set.
tji1=[]

def delete():
sctt=[]
for i in tjii1:
if ((O.bodies[i].state.pos[0])**2+(O.bodies[i].state.pos[1]-O.bodies[344713].state.pos[1])**2+(O.bodies[i].state.pos[2])**2-(jsdr)**2)<0:
if (O.bodies[i].state.pos[0])-(O.bodies[i].state.pos[2])*(tan(dct))<0:
sctt=sctt+[i]
tji2=list(set(tjii1)^set(sctt))
tjii1=tji2
tji2=[]
shu=len(sctt)
for i in sctt:
O.bodies.erase(i)
deleteshu=shu
T=O.iter
plot.addData(
i=O.iter,
deleteshu=deleteshu,
T=T,
)

globals()['delete']=locals()['delete']
--------
#in the O.engines, the PyRunner is :
--------
O.engines=[...,
PyRunner(iterPeriod=20,command="delete()"),
           ....,
            ]



When I run it,I get this notice:

 ---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
/home/dj/yade/install/bin/yade in <module>()

/home/dj/yade/install/bin/yade in delete()
      1 def delete():
      2     sctt=[]
----> 3     for i in tjii1:
      4         if ((O.bodies[i].state.pos[0])**2+(O.bodies[i].state.pos[1]-O.bodies[344713].state.pos[1])**2+(O.bodies[i].state.pos[2])**2-(jsdr)**2)<0:
      5             if (O.bodies[i].state.pos[0])-(O.bodies[i].state.pos[2])*(tan(dct))<0:

UnboundLocalError: local variable 'tjii1' referenced before assignment



Can you help me? Thank you very much

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