One way to get around this limitation in python is to use callable
classes instead of functions.
David

On Sat, Jun 14, 2008 at 10:42 AM, David Harvey
<[EMAIL PROTECTED]> wrote:
>
> On Jun 14, 2008, at 1:25 PM, Daniel Bump wrote:
>
>
> Some code that has been proposed by Nicolas Thiery
> for sage/combinat/families.py would create classes
> that have as attributes dictionaries of functions.
> However dumps(s) will raise an exception if s is
> such a class instance.
> Example: the simple reflections in a Weyl group. See:
> http://groups.google.com/group/sage-combinat-devel/msg/8b987cd471db3493?hl=en
> What it boils down to is this. The following is
> fine in native Python:
>
> import pickle
> def f(x): return x+1
>
> ...
>
> pickle.dumps(f)
>
> 'c__main__\nf\np0\n.'
>
> pickle.dumps({1:f})
>
> '(dp0\nI1\nc__main__\nf\np1\ns.'
> But if you try to run this from within Sage,
> both calls to dumps() will raise exceptions.
> Is this a bug in Sage?
>
> I actually thought you couldn't really pickle functions, even in plain
> python.
> http://docs.python.org/lib/node317.html
> "Note that functions (built-in and user-defined) are pickled by ``fully
> qualified'' name reference, not by value. This means that only the function
> name is pickled, along with the name of module the function is defined in.
> Neither the function's code, nor any of its function attributes are pickled.
> Thus the defining module must be importable in the unpickling environment,
> and the module must contain the named object, otherwise an exception will be
> raised."
> david
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@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-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to