Hi Brian,
 
Thanks for your reply.
 
In my case, "Spam" is a user defined "class" (It is not of standard type: int,string, float etc.,) .My intention is to cast a PyObject to the "Spam", which is a "Class" type..
 
When I try to execute the statement
 
Spam s = (Spam)ob.AsManagedObject(typeof(Spam));
 
the compilation went on smoothly, but during runtime, it has thrown an error "cannot convert object to target type".
 
I was wondering, do I have any functions which provides the casting.
 
Regards



From: Brian Lloyd [mailto:brian.d.lloyd@gmail.com]
Sent: Sonntag, 3. Februar 2008 04:52
To: Kaveripakam, Sathish
Cc: pythondotnet@python.org
Subject: Re: [Python.NET] converting Pyobject to user defined type data structures

Sathish - If I understand correctly what you're asking, I think you might need
to use the AsManagedObject method to retrieve the CLR object that a PyObject
wraps:

PyObject ob = GetMyObject(...)

Spam s = (Spam)ob.AsManagedObject(typeof(Spam));

hope this helps,

-Brian

On Jan 31, 2008 11:58 AM, Kaveripakam, Sathish <Sathish.Kaveripakam@phonak.com> wrote:
Hi All,
 
I am reading a PyObject from Python in C#. In C# code, I  would like to convert the PyObject to the user defined type. In this regard, I used the call:

<usrDefinedType> x  = (usrDefinedType) Convert.ChangeType(pyObjectInstance,typeof(usrDefinedType));

The compilation went on fine, but during runtime, I got an error saying: "Object must implement IConvertible".

I was wondering, is there any other way to convert the PyObjects to userdefined types ?

Regards

 


Legal Notice:
The information in this electronic transmission may contain confidential or legally privileged information and is intended solely for the individual(s) named above. If you are not an intended recipient or an authorized agent, you are hereby notified that reading, distributing, or otherwise disseminating, copying or taking any action based on the contents of this transmission is strictly prohibited. Any unauthorized interception of this transmission is illegal under law. If you have received this transmission in error, please notify the sender by telephone [at the number indicated above/on +41 58 928 0101] as soon as possible and then destroy all copies of this transmission.
 


_________________________________________________
Python.NET mailing list - PythonDotNet@python.org
http://mail.python.org/mailman/listinfo/pythondotnet


Legal Notice:
The information in this electronic transmission may contain confidential or legally privileged information and is intended solely for the individual(s) named above. If you are not an intended recipient or an authorized agent, you are hereby notified that reading, distributing, or otherwise disseminating, copying or taking any action based on the contents of this transmission is strictly prohibited. Any unauthorized interception of this transmission is illegal under law. If you have received this transmission in error, please notify the sender by telephone [at the number indicated above/on +41 58 928 0101] as soon as possible and then destroy all copies of this transmission.