[Original] Questions about message passing between Python and C #

Source: Internet
Author: User

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 #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.