On Feb 6, 2008 9:08 AM, Georg <[EMAIL PROTECTED]> wrote: > > Hi, > using sage-2.10.1 on a Debian Etch system, > look at the following short file called "example.sage": > > class BMV: > def __init__(self): > self.l = range(5) > def write(self): > save(self, 'foo') > M = BMV() > > it works as expected: > sage: load "example.sage" > sage: M.write() > sage: M = 0 > sage: M = load('foo') > sage: M.l > [0, 1, 2, 3, 4] > > but including the line > M.write() > into the script "example.sage": > > class BMV: > def __init__(self): > self.l = range(5) > def write(self): > save(self, 'foo') > M = BMV() > M.write() > > yields: > sage: load "example.sage" > --------------------------------------------------------------------------- > <class 'cPickle.PicklingError'> Traceback (most recent call > last) > > /home/georg/.sage/temp/HILBERT/7199/ > _home_georg_Daten_Sync_Software_Experimente_sage_save_example_sage_43.py > in <module>() > 10 > 11 M = BMV() > ---> 12 M.write() 13 > 14 > > /home/georg/.sage/temp/HILBERT/7199/ > _home_georg_Daten_Sync_Software_Experimente_sage_save_example_sage_43.py > in write(self) > 7 > 8 def write(self): > ----> 9 save(self, 'foo') > 10 > 11 M = BMV() > > /home/georg/Daten/Sync/Software/Experimente/sage/save/sage_object.pyx > in sage.structure.sage_object.save() > 482 > 483 > --> 484 > 485 > 486 > > <class 'cPickle.PicklingError'>: Can't pickle __main__.BMV: attribute > lookup __main__.BMV failed > WARNING: Failure executing file: </home/georg/.sage/temp/HILBERT/7199/ > _home_georg_Daten_Sync_Software_Experimente_sage_save_example_sage_43.py> > > > Is this a bug or why does it not work?
It's not a bug -- it is a feature of how Python works. You can't pickle user defined objects if the code that defines their class isn't in a place that Python can easily find any time in the future, e.g., in the Python site-packages directory. Hopefully somebody can say more... I'm at a nice talk right now at Sage Days 7. William William --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---