How to read user defined list from O.save('sample.yade.gz')

Asked by Leonard on 2020-03-06

Hi,

I define a list in script1.py, and save as sample.yade.gz.
And then I use script2.py to read the sample.yade.gz. In script2.py, I can not read the list defined in script1.py.
Is there any idea to make it?
Here is a MWE:
#######script1.py#####
O.bodies.append([
 sphere(center=(0,0,0),radius=.5,fixed=True),
 sphere((0,0,2),.5)
])

sandIds=[] ###this is an example list which I can not read from script2.py

for i in O.bodies:
    sandIds.append(i.id)

O.engines=[
 ForceResetter(),
 InsertionSortCollider([Bo1_Sphere_Aabb()]),
 InteractionLoop(
  [Ig2_Sphere_Sphere_ScGeom()],
  [Ip2_FrictMat_FrictMat_FrictPhys()],
  [Law2_ScGeom_FrictPhys_CundallStrack()]
 ),
 NewtonIntegrator(gravity=(0,0,-9.81),damping=0.1)
]

O.dt=.5e-4*PWaveTimeStep()
O.save('sample.yade.gz')
################

#########script2.py#########
O.load('sample.yade.gz')
print len(sandIds) ##yade version 2018.02b
##################
In script2, I can see all the particles, but I cannot get the sandIds list.
Is there any idea about how to pass these user defined lists (and other user defined variables) to another script?

Thanks,

Leonard

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Jan Stránský
Solved:
2020-03-06
Last query:
2020-03-06
Last reply:
2020-03-06
Best Jan Stránský (honzik) said : #1

Hi,
only C++ related data are O.save/O.load ed.
To save/load python data, use e.g. python pickle module
cheers
Jan

Leonard (z2521899293) said : #2

Thanks Jan Stránský, that solved my question.