My Computer environment is using. net framework4.5.1, if it doesn't work during debugging please note
I'm using the visual studion 2017,python component: http://ironpython.codeplex.com/releases/view/
The downloaded version is 2.7, and after the download installs, remember to introduce the following three DLLs under the installation path
(1) first of all, a simple function, in C # code to execute the Python string, the content is as Follows:
(2) C # call Python file:
In the current directory, create a new suffix named py file, the file name is amoutdisc.py content as follows
0.05= amtif amt>: = Amt-(amt*dicamt)
The file defines a Python file, then calls the Python file in C # code, gives the file a parameter, and, in particular, passes the parameters to the amt, and finally gets the Retamt variable in the Python file in the Code.
value, The following code is specified:
Scriptruntime Scriptruntime =Python.createruntime (); ScriptEngine Pytheng= Scriptruntime.getengine ("Python"); Scriptsource Scriptsource= Pytheng.createscriptsourcefromfile ("amoutdisc.py"); Scriptscope Scope=Pytheng.createscope (); //Scope. SetVariable ("prodcount", Convert.ToInt32 ("34343"));Scope. SetVariable ("Amt", Convert.todecimal ("434")); Scriptsource.execute (scope); DynamicA = Scope. GetVariable ("Retamt");
The results are as follows:
The call Succeeded.
C # invokes Python file execution