[Python.NET] converting Pyobject to user defined type data structures

Brian Lloyd brian.d.lloyd at gmail.com
Sun Feb 3 04:52:09 CET 2008

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


PyObject ob = GetMyObject(...)

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

hope this helps,


On Jan 31, 2008 11:58 AM, Kaveripakam, Sathish <
Sathish.Kaveripakam at 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 at python.org
> http://mail.python.org/mailman/listinfo/pythondotnet
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/pythondotnet/attachments/20080202/55c3b65a/attachment.htm 

More information about the PythonDotNet mailing list