utils.saveVars() and utils.loadVars()

Asked by Christian Jakob on 2011-08-10

Hi,

I want to save some variables with utils.saveVars() and load it in another script with utils.loadVars().

test script 1:

#!/usr/bin/python
# -*- coding: utf-8 -*-
a = 1

b = 2

c = 3
utils.saveVars('savedVars',a=a,b=b,c=c)

test script 2:

#!/usr/bin/python
# -*- coding: utf-8 -*-
utils.loadVars('savedVars')

error message:

Running script save-vars-test2.py
Traceback (most recent call last):
  File "/home/me/YADE/bin/yade-bzr2877", line 183, in runScript
    execfile(script,globals())
  File "save-vars-test2.py", line 3, in <module>
    utils.loadVars('savedVars')
  File "/home/me/YADE/lib/yade-bzr2877/py/yade/utils.py", line 67, in loadVars
    d=cPickle.loads(Omega().tags['pickledPythonVariablesDictionary'+mark])
KeyError: 'Invalid key: pickledPythonVariablesDictionarysavedVars.xml.'

???

Can I save my variables in another way, e.g. with the O.save() ?

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Christian Jakob
Solved:
2011-10-07
Last query:
2011-10-07
Last reply:
2011-10-06
Anton Gladky (gladky-anton) said : #1

Hi Christian,

yo use this function you need to save all your simulation, and then load it respectively [1].

So in your case the script 1 should look like:

===========
#!/usr/bin/python
# -*- coding: utf-8 -*-
a = 1

b = 2

c = 3
utils.saveVars('savedVars',a=a,b=b,c=c)
O.save("fileNameXML")
===========

test script 2:
===========
#!/usr/bin/python
# -*- coding: utf-8 -*-
O.load("fileNameXML")
utils.loadVars('savedVars')

print yade.params.savedVars.a
print yade.params.savedVars.b
print yade.params.savedVars.c
===========

[1] https://yade-dem.org/doc/yade.utils.html?highlight=savevars#yade.utils.saveVars

Christian Jakob (jakob-ifgt) said : #2

Thank you, Anton.