converting Pyobject to user defined type data structures
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. ********************
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
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. ********************
I’ve just applied some patches that were submitted to sourceforge by Joe Frayne and I (Brian Lloyd made us admins recently). They seem to work fine, and can be summarized as follows: -Bugfix in string test (revision 91, jburnett) -Added 64-bit support on Windows (revision 92, jburnett) -Possible bugfix for delegate support in .NET 2.x (revision 93, jburnett) -Support for conversion from python float to object (revision 94, anonymous) -Fix for binding to certain generic methods (revision 95, jfrayne) That said, I had two questions for anyone who can help J -It’s been a while since there’s been a “release” of python.net. The latest pre-compiled package is “pythonnet-2.0-alpha2-clr2.0.zip” from September of last year, and that doesn’t include a chunk of changes (even ignoring the changes above). Does anyone know what’s involved in bundling up a release and posting it? (Brian suggested that I ask here :). -When I applied the patches above, I forgot to add attribution to jfrayne in the submit log. I’d like to go back to add it (ie. prepend “Patch 1874988 from Joe Frayne” to the log), but I can’t seem to do it. Using TortoiseSVN, if I right-click on the appropriate log entry and use “edit log message”, I get the following error when I try to apply the change: ---- DAV request failed; it's possible that the repository's pre-revprop-change hook either failed or is non-existent At least one property change failed; repository is unchanged ---- Is there any way I can do this? John
John Burnett wrote:
-It’s been a while since there’s been a “release” of python.net. The latest pre-compiled package is “pythonnet-2.0-alpha2-clr2.0.zip” from September of last year, and that doesn’t include a chunk of changes (even ignoring the changes above). Does anyone know what’s involved in bundling up a release and posting it? (Brian suggested that I ask here :).
I can be of assistance since I've done the last releases. But I'm busy in the next couple of days with job interviews and the next Python 2.6 and 3.0 alpha releases. I'll see how I can squeeze Python.NET into my schedule.
-When I applied the patches above, I forgot to add attribution to jfrayne in the submit log. I’d like to go back to add it (ie. prepend “Patch 1874988 from Joe Frayne” to the log), but I can’t seem to do it. Using TortoiseSVN, if I right-click on the appropriate log entry and use “edit log message”, I get the following error when I try to apply the change:
SF.net's svn server may not support the feature. You can always revert the transaction (do a svn back merge) and submit the patch with the log message again. It's probably easier to start new files á la Python's Misc/ACKS and Misc/developers. Christian
Ok, thanks re: the release. As for the other issue, I just went ahead and committed a trivial change to vs_readme.txt to make a note about Joe. John -----Original Message----- From: pythondotnet-bounces@python.org [mailto:pythondotnet-bounces@python.org] On Behalf Of Christian Heimes Sent: Wednesday, February 27, 2008 3:17 AM To: pythondotnet@python.org Subject: Re: [Python.NET] Patches and new release John Burnett wrote:
-It’s been a while since there’s been a “release” of python.net. The latest pre-compiled package is “pythonnet-2.0-alpha2-clr2.0.zip” from September of last year, and that doesn’t include a chunk of changes (even ignoring the changes above). Does anyone know what’s involved in bundling up a release and posting it? (Brian suggested that I ask here :).
I can be of assistance since I've done the last releases. But I'm busy in the next couple of days with job interviews and the next Python 2.6 and 3.0 alpha releases. I'll see how I can squeeze Python.NET into my schedule.
-When I applied the patches above, I forgot to add attribution to jfrayne in the submit log. I’d like to go back to add it (ie. prepend “Patch 1874988 from Joe Frayne” to the log), but I can’t seem to do it. Using TortoiseSVN, if I right-click on the appropriate log entry and use “edit log message”, I get the following error when I try to apply the change:
SF.net's svn server may not support the feature. You can always revert the transaction (do a svn back merge) and submit the patch with the log message again. It's probably easier to start new files á la Python's Misc/ACKS and Misc/developers. Christian
I recommend splitting up the binaries and the source files when you do the release. The binaries should have names that make it really clear what platform and Python version they are for, e.g. pythonnet-2.0-alpha3-py2.5-clr2.0.zip pythonnet-2.0-alpha3-py2.4-mono2.0.zip I think that would make things a lot less confusing for people. - Feihong --- John Burnett <JBurnett@blizzard.com> wrote:
Iâve just applied some patches that were submitted to sourceforge by Joe Frayne and I (Brian Lloyd made us admins recently). They seem to work fine, and can be summarized as follows:
-Bugfix in string test (revision 91, jburnett)
-Added 64-bit support on Windows (revision 92, jburnett)
-Possible bugfix for delegate support in .NET 2.x (revision 93, jburnett)
-Support for conversion from python float to object (revision 94, anonymous)
-Fix for binding to certain generic methods (revision 95, jfrayne)
That said, I had two questions for anyone who can help J
-Itâs been a while since thereâs been a âreleaseâ of python.net. The latest pre-compiled package is âpythonnet-2.0-alpha2-clr2.0.zipâ from September of last year, and that doesnât include a chunk of changes (even ignoring the changes above). Does anyone know whatâs involved in bundling up a release and posting it? (Brian suggested that I ask here :).
-When I applied the patches above, I forgot to add attribution to jfrayne in the submit log. Iâd like to go back to add it (ie. prepend âPatch 1874988 from Joe Frayneâ to the log), but I canât seem to do it. Using TortoiseSVN, if I right-click on the appropriate log entry and use âedit log messageâ, I get the following error when I try to apply the change:
----
DAV request failed; it's possible that the repository's pre-revprop-change hook
either failed or is non-existent
At least one property change failed; repository is unchanged
----
Is there any way I can do this?
John
_________________________________________________ Python.NET mailing list - PythonDotNet@python.org http://mail.python.org/mailman/listinfo/pythondotnet
____________________________________________________________________________________ Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping
I spent the last few days working with a few people to get Python.NET working under Mono 1.9 on Mac OS X. I just checked in all the changes: -Added workaround to clrmod.c for Mono error: "Symbol not found: _environ" (a fix has been added to Mono SVN, according to Geoff Norton at Novell.) -Changed ordering of mono_config_parse(NULL) call in pynetinit.c, to handle latest changes to Mono embedding interface (a fix has been added to Mono SVN, according to Geoff Norton.) -Fixed TypeManager static constructor to properly handle .NET exceptions (thanks to Geoff Norton.) -Added to pynetinit.c to make clr.so search the site-packages folder of the currently running python to find the Python.Runtime.dll, instead of just the cwd (thanks to Peter Shinners and Wei Qiao at Blizzard Entertainment.) -Updated one of the Python.Runtime.dll.config files to map to .dylib instead of .so (thanks to Wei Qiao.) This should be looked at further, as there are a few of these files floating around... -Changed the Makefile to be self-contained and create the clr.so (thanks to Wei Qiao.) This should be looked at further, as running setup.py currently builds the clr.so, but gives an error afterwards. -Updated README.txt a bit more. Joe
participants (6)
-
Brian Lloyd
-
Christian Heimes
-
Feihong Hsu
-
Joe Frayne
-
John Burnett
-
Kaveripakam, Sathish