[IronPython] DLR: ActionBinder and ParseSourceCode

2008-03-26 Thread Marius
Hi,

I wonder if that's a bug or by design.

Expression returned by Ast.Action.Operator(Operators.NotEquals,
Ast.Null(), Ast.Null()) [which I believe is equivalent to null !=
null] evaluates to True, though False could be expected (overriding
MakeRule for this special case does the trick).

Having returned LambdaExpression from LanguageContext.ParseSourceCode
which has return type of void, produces
"System.InvalidProgramException : Common Language Runtime detected an
invalid program", changing return type to object solves the problem.

Marius
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] deepcopy() in IRONPY

2008-03-26 Thread Bernd Viehmann
Hi Curt,

thanks, but I am not allowed to install FePy on the Production-Server. So I
need a solution with pure IronPython ;-).

Regards

  Bernd


2008/3/26, Curt Hagenlocher <[EMAIL PROTECTED]>:
>
> On Wed, Mar 26, 2008 at 8:04 AM, Bernd Viehmann
> <[EMAIL PROTECTED]> wrote:
> >
> > How can i use the copy-module-functionality in ipy?
>
>
> Have you tried just using the py files that ship with CPython?
>
> You can get a distribution of IronPython that incorporates these files
> from Seo's FePy project at http://fepy.sourceforge.net
>
>
> --
> Curt Hagenlocher
> [EMAIL PROTECTED]
> ___
> Users mailing list
> Users@lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] Question about serialization

2008-03-26 Thread Sanghyeon Seo
2008/3/26, Paul Turbett <[EMAIL PROTECTED]>:
>  It seems that whilst serializing .NET classes is trivial, and serializing
> python classes is trivial, serializing something that touches both is
> proving quite difficult.
>
>  Any further suggestions gratefully received!

I suggest using copy_reg to register .NET class to Python pickle mechanism.
See: http://docs.python.org/lib/module-copyreg.html

I actually implemented this back in the last year.
http://lists.ironpython.com/pipermail/users-ironpython.com/2007-February/004509.html
http://fepy.svn.sourceforge.net/svnroot/fepy/trunk/fepy/pickle.py

-- 
Seo Sanghyeon
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] Question about serialization

2008-03-26 Thread Curt Hagenlocher
I was thinking that Python's lack of a global namespace for classes would be
a problem -- but of course it's not because you'd actually be looking in the
CLR namespace.  So you could just fail the deserialize if the CLR base class
doesn't already exist.

It would still be nice to be able to auto-load an assembly when the base
class is strongly-named.

On Wed, Mar 26, 2008 at 8:42 AM, Dino Viehland <[EMAIL PROTECTED]>
wrote:

>  My guess is you'd restrict it only to .NET objects which are marked as
> being serializable.  Then you'd ask the object to serialize it's self and
> then stuff that into the pickle stream along w/ the extra Python info.
> That's probably include a type name which you'd just load and see what you
> got – much like how cPickle does an import and uses what it gets when it's
> loading a global.
>
>
>
> *From:* [EMAIL PROTECTED] [mailto:
> [EMAIL PROTECTED] *On Behalf Of *Curt Hagenlocher
> *Sent:* Wednesday, March 26, 2008 8:31 AM
> *To:* Discussion of IronPython
> *Subject:* Re: [IronPython] Question about serialization
>
>
>
> This is an interesting problem. Python's pickle writes out enough data to
> rebuild the object entirely -- including the class definition, if the object
> is a user-defined type.  How do you accurately write out a class definition
> for a C# base class?  Would you restrict it to strongly named classes?
>
>
>
>
> On Wed, Mar 26, 2008 at 4:55 AM, Paul Turbett <[EMAIL PROTECTED]> wrote:
>
> Thanks Michael for the advice. Must appreciated. Unfortunately I hasn't
> worked out yet tho :(
>
> I can use pickle from C# using Evaluate, or from within a Python class, on
> a "pure" Python object. However any attempt at pickling a python object that
> derives from a C# base result in an exception like this:
> Cannot convert MyObject() to Int32
>
> Exploring further, I came across Ops.GetDynamicType() and
> Ops.GetAttrsNames() which I thought might be helpful to get the attributes
> of an object and serialize it somehow (manually), but GetAttrNames requires
> an ICallerContext, and I can't see how to get one of those.
>
> It seems that whilst serializing .NET classes is trivial, and serializing
> python classes is trivial, serializing something that touches both is
> proving quite difficult.
>
> Any further suggestions gratefully received!
>
> Thanks, Paul
>
> Michael Foord wrote:
>
> Paul Turbett wrote:
>
>
>
> Hi,
>
>
>
> I'm using IP as a scripting engine in a C# app. I have various Python
>
> classes that derive from a C# base class, and have there own additional
>
> data & functionality.
>
>
>
> I would like to be able to serialize instances of the Python classes
>
> from the C# host for persistence across sessions. Using the standard
>
> BinaryFormatter with the Serializable attribute is not working - I get
>
> an error about the python class not being marked as serializable (the C#
>
> base class is marked as serializable though).
>
>
>
> How can I serialize python objects from C#? Should I use reflection to
>
> roll my own serializer, or is there something in one of the lesser
>
> documented assemblies like Ops I should use?
>
>
>
>
>
> Typically for serializing Python objects you would use pickle [1]. The
>
> 'dumps' function returns a string (make sure you use the text protocol
>
> for IronPython).
>
>
>
> You could then execute code inside the Python engine to serialize /
>
> deserialize objects. I've not tried this for instances that inherit from
>
> C# base classes - but it should work fine. :-)
>
>
>
> Michael Foord
>
> http://www.ironpythoninaction.com
>
>
>
> .. [1] http://docs.python.org/lib/module-pickle.html
>
>
>
>
>
> I'm using IP 1.1.1 (but will move to 2.0 if that will help). Any
>
> pointers & advice greatly appreciated!
>
>
>
> Thanks, Paul
>
> ___
>
> Users mailing list
>
> Users@lists.ironpython.com
>
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
>
>
>
> ___
>
> Users mailing list
>
> Users@lists.ironpython.com
>
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
>
>
>
>
>
>
> ___
> Users mailing list
> Users@lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
>
> ___
> Users mailing list
> Users@lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] Question about serialization

2008-03-26 Thread Dino Viehland
My guess is you'd restrict it only to .NET objects which are marked as being 
serializable.  Then you'd ask the object to serialize it's self and then stuff 
that into the pickle stream along w/ the extra Python info.  That's probably 
include a type name which you'd just load and see what you got - much like how 
cPickle does an import and uses what it gets when it's loading a global.

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Curt Hagenlocher
Sent: Wednesday, March 26, 2008 8:31 AM
To: Discussion of IronPython
Subject: Re: [IronPython] Question about serialization

This is an interesting problem. Python's pickle writes out enough data to 
rebuild the object entirely -- including the class definition, if the object is 
a user-defined type.  How do you accurately write out a class definition for a 
C# base class?  Would you restrict it to strongly named classes?


On Wed, Mar 26, 2008 at 4:55 AM, Paul Turbett <[EMAIL PROTECTED]> wrote:
Thanks Michael for the advice. Must appreciated. Unfortunately I hasn't worked 
out yet tho :(

I can use pickle from C# using Evaluate, or from within a Python class, on a 
"pure" Python object. However any attempt at pickling a python object that 
derives from a C# base result in an exception like this:
Cannot convert MyObject() to Int32

Exploring further, I came across Ops.GetDynamicType() and Ops.GetAttrsNames() 
which I thought might be helpful to get the attributes of an object and 
serialize it somehow (manually), but GetAttrNames requires an ICallerContext, 
and I can't see how to get one of those.

It seems that whilst serializing .NET classes is trivial, and serializing 
python classes is trivial, serializing something that touches both is proving 
quite difficult.

Any further suggestions gratefully received!

Thanks, Paul

Michael Foord wrote:

Paul Turbett wrote:



Hi,



I'm using IP as a scripting engine in a C# app. I have various Python

classes that derive from a C# base class, and have there own additional

data & functionality.



I would like to be able to serialize instances of the Python classes

from the C# host for persistence across sessions. Using the standard

BinaryFormatter with the Serializable attribute is not working - I get

an error about the python class not being marked as serializable (the C#

base class is marked as serializable though).



How can I serialize python objects from C#? Should I use reflection to

roll my own serializer, or is there something in one of the lesser

documented assemblies like Ops I should use?





Typically for serializing Python objects you would use pickle [1]. The

'dumps' function returns a string (make sure you use the text protocol

for IronPython).



You could then execute code inside the Python engine to serialize /

deserialize objects. I've not tried this for instances that inherit from

C# base classes - but it should work fine. :-)



Michael Foord

http://www.ironpythoninaction.com



.. [1] http://docs.python.org/lib/module-pickle.html





I'm using IP 1.1.1 (but will move to 2.0 if that will help). Any

pointers & advice greatly appreciated!



Thanks, Paul

___

Users mailing list

Users@lists.ironpython.com

http://lists.ironpython.com/listinfo.cgi/users-ironpython.com





___

Users mailing list

Users@lists.ironpython.com

http://lists.ironpython.com/listinfo.cgi/users-ironpython.com






___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] Question about serialization

2008-03-26 Thread Curt Hagenlocher
Ooh, I was unaware of __reduce__ and __reduce_ex__; thanks.


On Wed, Mar 26, 2008 at 8:36 AM, Dino Viehland <[EMAIL PROTECTED]>
wrote:

>  Unfortunately I don't think what you want will work.  If it's your .NET
> class you could implement __reduce_ex__ and I think we'd pick it up and use
> that for the serialization.  But if it's some arbitrary framework class then
> you'll run into trouble.  On IronPython 2.0 you could have an extension
> class w/ the __reduce_ex__ function, have an ExtensionTypeAttribute that
> links the .NET base class and the extension class, and then call
> RuntimeHelpers.RegisterAssembly and we'd pick up the extension method.
>
>
>
> Also, we do have a feature request for this on CodePlex:
> http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=13401
> Voting on it would raise its priority and we'd be more likely to do it
> sooner rather than later.
>
>
>
> *From:* [EMAIL PROTECTED] [mailto:
> [EMAIL PROTECTED] *On Behalf Of *Paul Turbett
> *Sent:* Wednesday, March 26, 2008 4:56 AM
> *To:* Discussion of IronPython
> *Subject:* Re: [IronPython] Question about serialization
>
>
>
> Thanks Michael for the advice. Must appreciated. Unfortunately I hasn't
> worked out yet tho :(
>
> I can use pickle from C# using Evaluate, or from within a Python class, on
> a "pure" Python object. However any attempt at pickling a python object that
> derives from a C# base result in an exception like this:
> Cannot convert MyObject() to Int32
>
> Exploring further, I came across Ops.GetDynamicType() and
> Ops.GetAttrsNames() which I thought might be helpful to get the attributes
> of an object and serialize it somehow (manually), but GetAttrNames requires
> an ICallerContext, and I can't see how to get one of those.
>
> It seems that whilst serializing .NET classes is trivial, and serializing
> python classes is trivial, serializing something that touches both is
> proving quite difficult.
>
> Any further suggestions gratefully received!
>
> Thanks, Paul
>
> Michael Foord wrote:
>
> Paul Turbett wrote:
>
>
>
> Hi,
>
>
>
> I'm using IP as a scripting engine in a C# app. I have various Python
>
> classes that derive from a C# base class, and have there own additional
>
> data & functionality.
>
>
>
> I would like to be able to serialize instances of the Python classes
>
> from the C# host for persistence across sessions. Using the standard
>
> BinaryFormatter with the Serializable attribute is not working - I get
>
> an error about the python class not being marked as serializable (the C#
>
> base class is marked as serializable though).
>
>
>
> How can I serialize python objects from C#? Should I use reflection to
>
> roll my own serializer, or is there something in one of the lesser
>
> documented assemblies like Ops I should use?
>
>
>
>
>
>
>
> Typically for serializing Python objects you would use pickle [1]. The
>
> 'dumps' function returns a string (make sure you use the text protocol
>
> for IronPython).
>
>
>
> You could then execute code inside the Python engine to serialize /
>
> deserialize objects. I've not tried this for instances that inherit from
>
> C# base classes - but it should work fine. :-)
>
>
>
> Michael Foord
>
> http://www.ironpythoninaction.com
>
>
>
> .. [1] http://docs.python.org/lib/module-pickle.html
>
>
>
>
>
> I'm using IP 1.1.1 (but will move to 2.0 if that will help). Any
>
> pointers & advice greatly appreciated!
>
>
>
> Thanks, Paul
>
> ___
>
> Users mailing list
>
> Users@lists.ironpython.com
>
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
>
>
>
>
>
> ___
>
> Users mailing list
>
> Users@lists.ironpython.com
>
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
>
>
>
>
>
> ___
> Users mailing list
> Users@lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] Question about serialization

2008-03-26 Thread Dino Viehland
Unfortunately I don't think what you want will work.  If it's your .NET class 
you could implement __reduce_ex__ and I think we'd pick it up and use that for 
the serialization.  But if it's some arbitrary framework class then you'll run 
into trouble.  On IronPython 2.0 you could have an extension class w/ the 
__reduce_ex__ function, have an ExtensionTypeAttribute that links the .NET base 
class and the extension class, and then call RuntimeHelpers.RegisterAssembly 
and we'd pick up the extension method.

Also, we do have a feature request for this on CodePlex: 
http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=13401  Voting 
on it would raise its priority and we'd be more likely to do it sooner rather 
than later.

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Paul Turbett
Sent: Wednesday, March 26, 2008 4:56 AM
To: Discussion of IronPython
Subject: Re: [IronPython] Question about serialization

Thanks Michael for the advice. Must appreciated. Unfortunately I hasn't worked 
out yet tho :(

I can use pickle from C# using Evaluate, or from within a Python class, on a 
"pure" Python object. However any attempt at pickling a python object that 
derives from a C# base result in an exception like this:
Cannot convert MyObject() to Int32

Exploring further, I came across Ops.GetDynamicType() and Ops.GetAttrsNames() 
which I thought might be helpful to get the attributes of an object and 
serialize it somehow (manually), but GetAttrNames requires an ICallerContext, 
and I can't see how to get one of those.

It seems that whilst serializing .NET classes is trivial, and serializing 
python classes is trivial, serializing something that touches both is proving 
quite difficult.

Any further suggestions gratefully received!

Thanks, Paul

Michael Foord wrote:

Paul Turbett wrote:



Hi,



I'm using IP as a scripting engine in a C# app. I have various Python

classes that derive from a C# base class, and have there own additional

data & functionality.



I would like to be able to serialize instances of the Python classes

from the C# host for persistence across sessions. Using the standard

BinaryFormatter with the Serializable attribute is not working - I get

an error about the python class not being marked as serializable (the C#

base class is marked as serializable though).



How can I serialize python objects from C#? Should I use reflection to

roll my own serializer, or is there something in one of the lesser

documented assemblies like Ops I should use?







Typically for serializing Python objects you would use pickle [1]. The

'dumps' function returns a string (make sure you use the text protocol

for IronPython).



You could then execute code inside the Python engine to serialize /

deserialize objects. I've not tried this for instances that inherit from

C# base classes - but it should work fine. :-)



Michael Foord

http://www.ironpythoninaction.com



.. [1] http://docs.python.org/lib/module-pickle.html





I'm using IP 1.1.1 (but will move to 2.0 if that will help). Any

pointers & advice greatly appreciated!



Thanks, Paul

___

Users mailing list

Users@lists.ironpython.com

http://lists.ironpython.com/listinfo.cgi/users-ironpython.com







___

Users mailing list

Users@lists.ironpython.com

http://lists.ironpython.com/listinfo.cgi/users-ironpython.com





___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] Question about serialization

2008-03-26 Thread Curt Hagenlocher
This is an interesting problem. Python's pickle writes out enough data to
rebuild the object entirely -- including the class definition, if the object
is a user-defined type.  How do you accurately write out a class definition
for a C# base class?  Would you restrict it to strongly named classes?


On Wed, Mar 26, 2008 at 4:55 AM, Paul Turbett <[EMAIL PROTECTED]> wrote:

> Thanks Michael for the advice. Must appreciated. Unfortunately I hasn't
> worked out yet tho :(
>
> I can use pickle from C# using Evaluate, or from within a Python class, on
> a "pure" Python object. However any attempt at pickling a python object that
> derives from a C# base result in an exception like this:
> Cannot convert MyObject() to Int32
>
> Exploring further, I came across Ops.GetDynamicType() and
> Ops.GetAttrsNames() which I thought might be helpful to get the attributes
> of an object and serialize it somehow (manually), but GetAttrNames requires
> an ICallerContext, and I can't see how to get one of those.
>
> It seems that whilst serializing .NET classes is trivial, and serializing
> python classes is trivial, serializing something that touches both is
> proving quite difficult.
>
> Any further suggestions gratefully received!
>
> Thanks, Paul
>
> Michael Foord wrote:
>
> Paul Turbett wrote:
>
>
> Hi,
>
> I'm using IP as a scripting engine in a C# app. I have various Python
> classes that derive from a C# base class, and have there own additional
> data & functionality.
>
> I would like to be able to serialize instances of the Python classes
> from the C# host for persistence across sessions. Using the standard
> BinaryFormatter with the Serializable attribute is not working - I get
> an error about the python class not being marked as serializable (the C#
> base class is marked as serializable though).
>
> How can I serialize python objects from C#? Should I use reflection to
> roll my own serializer, or is there something in one of the lesser
> documented assemblies like Ops I should use?
>
>
>
> Typically for serializing Python objects you would use pickle [1]. The
> 'dumps' function returns a string (make sure you use the text protocol
> for IronPython).
>
> You could then execute code inside the Python engine to serialize /
> deserialize objects. I've not tried this for instances that inherit from
> C# base classes - but it should work fine. :-)
>
> Michael Foordhttp://www.ironpythoninaction.com
>
> .. [1] http://docs.python.org/lib/module-pickle.html
>
>   I'm using IP 1.1.1 (but will move to 2.0 if that will help). Any
> pointers & advice greatly appreciated!
>
> Thanks, Paul
> ___
> Users mailing [EMAIL 
> PROTECTED]://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
> ___
> Users mailing [EMAIL 
> PROTECTED]://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
>
> ___
> Users mailing list
> Users@lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] deepcopy() in IRONPY

2008-03-26 Thread Curt Hagenlocher
On Wed, Mar 26, 2008 at 8:04 AM, Bernd Viehmann
<[EMAIL PROTECTED]> wrote:
>
> How can i use the copy-module-functionality in ipy?

Have you tried just using the py files that ship with CPython?

You can get a distribution of IronPython that incorporates these files
from Seo's FePy project at http://fepy.sourceforge.net

--
Curt Hagenlocher
[EMAIL PROTECTED]
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


[IronPython] deepcopy() in IRONPY

2008-03-26 Thread Bernd Viehmann
Hi,

i am news to this list, so let me give a short introduction of myself.

My name is Bernd from Aachen in Germany (near the border to Netherlands and
Belgium) and I am working with python for some time now. In the moment i am
shifting some of my old python-scripts into ironpython because the "normal"
python will not be installed on our 64bit windows servers. Ironpython as a
Microsoft-product is more welcome in the eyes of our customer.

So my (first) question regarding copy of object-instances:

How can i use the copy-module-functionality in ipy? Is there something
comparable in DOT.NET? Are a modern way to copy instance-data instead of
references.

Thank you very much and kind regards.

Bernd
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] SetSocketOption error on OSX

2008-03-26 Thread Sanghyeon Seo
2008/3/26, Duncan Foster <[EMAIL PROTECTED]>:
>  Traceback (most recent call last):
>   File httplib, line unknown, in getreply
>   File httplib, line unknown, in getresponse
>   File httplib, line unknown, in __init__
>   File System, line unknown, in set_ReceiveBufferSize
>   File System, line unknown, in SetSocketOption
>  WindowsError: Invalid arguments

This is likely to be a Mono bug, probably specific to Mac OS X.

-- 
Seo Sanghyeon
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


[IronPython] SetSocketOption error on OSX

2008-03-26 Thread Duncan Foster
Hi,
Motivated by the talks at PyCon I've started looking at ironPython.
I've been trying to get some code that uses xmlrpclib working, but
get:

Traceback (most recent call last):
  File httplib, line unknown, in getreply
  File httplib, line unknown, in getresponse
  File httplib, line unknown, in __init__
  File System, line unknown, in set_ReceiveBufferSize
  File System, line unknown, in SetSocketOption
WindowsError: Invalid arguments

I've tried both IronPython-1.1.1 & IPCE-r7 , and:
myhost:~/IronPython dcf$ mono --version
Mono JIT compiler version 1.9 (tarball)
Copyright (C) 2002-2007 Novell, Inc and Contributors. www.mono-project.com
TLS:   normal
GC:Included Boehm (with typed GC)
SIGSEGV:   normal
Notification:  Thread + polling
Architecture:  x86
Disabled:  none

Any help would be much appreciated!

Thanks,
Duncan
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] Question about serialization

2008-03-26 Thread Paul Turbett
Thanks Michael for the advice. Must appreciated. Unfortunately I hasn't 
worked out yet tho :(


I can use pickle from C# using Evaluate, or from within a Python class, 
on a "pure" Python object. However any attempt at pickling a python 
object that derives from a C# base result in an exception like this:

Cannot convert MyObject() to Int32

Exploring further, I came across Ops.GetDynamicType() and 
Ops.GetAttrsNames() which I thought might be helpful to get the 
attributes of an object and serialize it somehow (manually), but 
GetAttrNames requires an ICallerContext, and I can't see how to get one 
of those.


It seems that whilst serializing .NET classes is trivial, and 
serializing python classes is trivial, serializing something that 
touches both is proving quite difficult.


Any further suggestions gratefully received!

Thanks, Paul

Michael Foord wrote:

Paul Turbett wrote:
  

Hi,

I'm using IP as a scripting engine in a C# app. I have various Python 
classes that derive from a C# base class, and have there own additional 
data & functionality.


I would like to be able to serialize instances of the Python classes 
from the C# host for persistence across sessions. Using the standard 
BinaryFormatter with the Serializable attribute is not working - I get 
an error about the python class not being marked as serializable (the C# 
base class is marked as serializable though).


How can I serialize python objects from C#? Should I use reflection to 
roll my own serializer, or is there something in one of the lesser 
documented assemblies like Ops I should use?
  



Typically for serializing Python objects you would use pickle [1]. The 
'dumps' function returns a string (make sure you use the text protocol 
for IronPython).


You could then execute code inside the Python engine to serialize / 
deserialize objects. I've not tried this for instances that inherit from 
C# base classes - but it should work fine. :-)


Michael Foord
http://www.ironpythoninaction.com

.. [1] http://docs.python.org/lib/module-pickle.html

  
I'm using IP 1.1.1 (but will move to 2.0 if that will help). Any 
pointers & advice greatly appreciated!


Thanks, Paul
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
  



___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

  


___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com