Description of the problem:
With Python's powerful network capabilities and rich open source components and a good framework for developing Windows Form programs in C #, Python and C # Hybrid programming can effectively combine the strengths of both to quickly develop products.
However, the transmission of information/data between the two has become a primary problem.
Solution Ideas:
It is a preferred technique to facilitate object conversion between the two (the introduction of JSON is no longer described, and reference is made to [1]). Now that we've chosen to use JSON as a message-passing format, there are two scenarios in which we can deal with this problem:
I. Passing a JSON string through an intermediate file
In Python, you assemble the object that you want to pass to C # into a list, convert it to a JSON string, write the string to the file, and then read the file in the C # side and deserialize it into the list of objects.
Words not much to say, directly on the code:
Python-Side code:
Note: Only the core code is posted here. [2] You can refer to how to convert a custom Python to a JSON string.
C # side code:
Second, pass the JSON string through the return value
The JSON string that converts the list of objects to the Python side directly returns, captures the return value directly on the C # side, and deserializes it into the list of objects, with the following code:
Python side
C # End
This approach omits read and write operations to intermediate files, which is less time-and-space overhead for the program to run.
Reference documents:
"1" Introduction to JSON http://www.json.org/json-zh.html
"2" uses JSON as an intermediate file for object conversions when mixed programming with Python and C # http://www.cnblogs.com/chaosimple/p/4035693.html
"3" best-return a value from a Python script http://stackoverflow.com/questions/18231415/ Best-way-to-return-a-value-from-a-python-script
[Original] Questions about message passing between Python and C #