henon / Python.Included

A Python.NET based framework enabling .NET libraries to call into Python packages without depending on a local Python installation.
MIT License
313 stars 51 forks source link

How to pass data between c# and python? #26

Closed zeugmato closed 3 years ago

zeugmato commented 3 years ago

I noticed the two way: "dynamic" key words and "PythonEngine.Exec( )" function,but if I have hundreds lines of python codes to excute,there are countless "if else" and "class " and other functions, obviously the two above ways are not suitable. So how to pass some values to c#?And how to pass some values from c# to python codes?

henon commented 3 years ago

You can check out the source code of Numpy.NET which calls numpy in Python and passes data in and out. Also check out the documentation of pythonnet.

zeugmato commented 3 years ago

By myself I create a lazy method: define a function in a1.py file , e.g., def test(), this function has a return value, then import the a1, call the test() function directly:a1.test() .It worked!

henon commented 3 years ago

great. then I can close this.