I am trying my hand at pickling with Blender, but I am running into trouble right from the start. I have the following sample code to test the concept:
#!/usr/bin/python # Filename: pickling.py import cPickle as p class TestClass: pass filename = 'file.data' var = TestClass() #var = 1 print var f = file( filename, 'w' ) p.dump( var, f ) f.close() del var f = file( filename ) storedvar = p.load( f ) print storedvar
# pickling.py <__main__.TestClass instance at 0x2af2f15d7560> <__main__.TestClass instance at 0x2af2f15d7560>
Looks good to me. So now when I try to run that script with Blender, I get the following:
# /usr/bin/blender -P bin/pickling.py Compiled with Python version 2.4. Checking for installed Python... got it! <__main__.TestClass instance at 0x2aaaaac0b290> Traceback (most recent call last): File "pickling.py", line 21, in ? AttributeError: 'module' object has no attribute 'TestClass' Error executing Python script from command-line: bin/pickling.py (at line 21). Blender quit
If I change to ‘var = 1’, then the code works just fine. What is it about classes that I am missing?