DotnetPythonHandler 1.0.3
See the version list below for details.
dotnet add package DotnetPythonHandler --version 1.0.3
NuGet\Install-Package DotnetPythonHandler -Version 1.0.3
<PackageReference Include="DotnetPythonHandler" Version="1.0.3" />
<PackageVersion Include="DotnetPythonHandler" Version="1.0.3" />
<PackageReference Include="DotnetPythonHandler" />
paket add DotnetPythonHandler --version 1.0.3
#r "nuget: DotnetPythonHandler, 1.0.3"
#addin nuget:?package=DotnetPythonHandler&version=1.0.3
#tool nuget:?package=DotnetPythonHandler&version=1.0.3
<a name='assembly'></a>
PythonHandler
This package is a wrapper around IronPython allowing for easily running Python scripts.
Create an IronPython Handler
using PythonHandler;
// Create a handler without additional module search paths.
Handler pythonHandler = new Handler();
// Create a handler with additional module search paths.
var searchPaths = new List<string>() {"/custom/python/lib"}
Handler pythonHandler = new Handler(searchPaths);
Run from String
using PythonHandler;
Handler pythonHandler = new Handler();
// Run an IronPython script from a string without a return value.
pythonHandler.RunFromString("import sys; sysversion = sys.version");
// Run an IronPython script from a string with a return value.
var result = pythonHandler.RunFromString<string>("import sys; sysversion = sys.version", "sysversion");
// Run an IronPython script from a string with a return value and additional variables.
var tdict = new Dictionary<string, object>();
tdict.Add("testvar", "1ece43cc-b45a-4f97-ba69-5106f23e3932");
var result = pythonHandler.RunFromString<string>("import sys", "testvar", tdict);
Run from File
using PythonHandler;
Handler pythonHandler = new Handler();
// Run an IronPython script from a file without a return value.
pythonHandler.RunFromFile("import sys; sysversion = sys.version");
// Run an IronPython script from a file with a return value.
var result = pythonHandler.RunFromFile<string>("import sys; sysversion = sys.version", "sysversion");
// Run an IronPython script from a file with a return value and additional variables.
var tdict = new Dictionary<string, object>();
tdict.Add("testvar", "1ece43cc-b45a-4f97-ba69-5106f23e3932");
var result = pythonHandler.RunFromFile<string>("import sys", "testvar", tdict);
Contents
- PythonHandler
- Create an IronPython
Handler
- Run from String
- Run from File
- Contents
- Handler
type
- #ctor()
constructor
- #ctor(additionalSearchPaths)
constructor
- _scriptEngine
constants
- RunFromFile(scriptFile)
method
- RunFromFile(scriptFile,variables)
method
- RunFromFile``1(scriptFile,returnVariable)
method
- RunFromFile``1(scriptFile,returnVariable,variables)
method
- RunFromString(code)
method
- RunFromString(code,variables)
method
- RunFromString``1(code,returnVariable)
method
- RunFromString``1(code,returnVariable,variables)
method
- Handler
- Create an IronPython
<a name='T-PythonHandler-Handler'></a>
Handler type
Namespace
PythonHandler
Summary
Class Handler
handles execution of Python scripts using IronPython.
<a name='M-PythonHandler-Handler-#ctor'></a>
#ctor() constructor
Summary
This constructor initializes a new Handler
.
Parameters
This constructor has no parameters.
<a name='M-PythonHandler-Handler-#ctor-System-Collections-Generic-ICollection{System-String}-'></a>
#ctor(additionalSearchPaths) constructor
Summary
This constructor initializes a new Handler
with additional module search paths.
Parameters
Name | Type | Description |
---|---|---|
additionalSearchPaths | System.Collections.Generic.ICollection{System.String} | additionalSearchPaths is a collection of addtional module search paths to add to the IronPython scope. |
<a name='F-PythonHandler-Handler-_scriptEngine'></a>
_scriptEngine constants
Summary
Instance variable _scriptEngine
is the IronPython ScriptEngine
used for hosting IronPython.
<a name='M-PythonHandler-Handler-RunFromFile-System-String-'></a>
RunFromFile(scriptFile) method
Summary
This method runs a Python script.
Parameters
Name | Type | Description |
---|---|---|
scriptFile | System.String | scriptFile is the path to the Python script to execute. |
<a name='M-PythonHandler-Handler-RunFromFile-System-String,System-Collections-Generic-Dictionary{System-String,System-Object}-'></a>
RunFromFile(scriptFile,variables) method
Summary
This method runs a Python script.
Parameters
Name | Type | Description |
---|---|---|
scriptFile | System.String | scriptFile is the path to the Python script to execute. |
variables | System.Collections.Generic.Dictionary{System.String,System.Object} | variables is an Dictionary containing the key/values of variables to set. |
<a name='M-PythonHandler-Handler-RunFromFile``1-System-String,System-String-'></a>
RunFromFile``1(scriptFile,returnVariable) method
Summary
This method runs a Python script.
Returns
The value of the returnVariable
from the scope.
Parameters
Name | Type | Description |
---|---|---|
scriptFile | System.String | scriptFile is the path to the Python script to execute. |
returnVariable | System.String | returnVariable is the variable to read from the scope. |
Generic Types
Name | Description |
---|---|
TResult | The type of data to return. |
Exceptions
Name | Description |
---|---|
System.Collections.Generic.KeyNotFoundException | The returnVariable was not found. |
<a name='M-PythonHandler-Handler-RunFromFile``1-System-String,System-String,System-Collections-Generic-Dictionary{System-String,System-Object}-'></a>
RunFromFile``1(scriptFile,returnVariable,variables) method
Summary
This method runs a Python script.
Returns
The value of the returnVariable
from the scope.
Parameters
Name | Type | Description |
---|---|---|
scriptFile | System.String | scriptFile is the path to the Python script to execute. |
returnVariable | System.String | returnVariable is the variable to read from the scope. |
variables | System.Collections.Generic.Dictionary{System.String,System.Object} | variables is an Dictionary containing the key/values of variables to set. |
Generic Types
Name | Description |
---|---|
TResult | The type of data to return. |
Exceptions
Name | Description |
---|---|
System.Collections.Generic.KeyNotFoundException | The returnVariable was not found. |
<a name='M-PythonHandler-Handler-RunFromString-System-String-'></a>
RunFromString(code) method
Summary
This method runs a string of Python code.
Parameters
Name | Type | Description |
---|---|---|
code | System.String | code is the Python string to execute. |
<a name='M-PythonHandler-Handler-RunFromString-System-String,System-Collections-Generic-Dictionary{System-String,System-Object}-'></a>
RunFromString(code,variables) method
Summary
This method runs a string of Python code.
Parameters
Name | Type | Description |
---|---|---|
code | System.String | code is the Python string to execute. |
variables | System.Collections.Generic.Dictionary{System.String,System.Object} | variables is an Dictionary containing the key/values of variables to set. |
<a name='M-PythonHandler-Handler-RunFromString``1-System-String,System-String-'></a>
RunFromString``1(code,returnVariable) method
Summary
This method runs a string of Python code.
Returns
The value of the returnVariable
from the scope.
Parameters
Name | Type | Description |
---|---|---|
code | System.String | code is the Python string to execute. |
returnVariable | System.String | returnVariable is the variable to read from the scope. |
Generic Types
Name | Description |
---|---|
TResult | The type of data to return. |
Exceptions
Name | Description |
---|---|
System.Collections.Generic.KeyNotFoundException | The returnVariable was not found. |
<a name='M-PythonHandler-Handler-RunFromString``1-System-String,System-String,System-Collections-Generic-Dictionary{System-String,System-Object}-'></a>
RunFromString``1(code,returnVariable,variables) method
Summary
This method runs a string of Python code.
Returns
The value of the returnVariable
from the scope.
Parameters
Name | Type | Description |
---|---|---|
code | System.String | code is the Python string to execute. |
returnVariable | System.String | returnVariable is the variable to read from the scope. |
variables | System.Collections.Generic.Dictionary{System.String,System.Object} | variables is an Dictionary containing the key/values of variables to set. |
Generic Types
Name | Description |
---|---|
TResult | The type of data to return. |
Exceptions
Name | Description |
---|---|
System.Collections.Generic.KeyNotFoundException | The returnVariable was not found. |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- IronPython (>= 3.4.0)
- IronPython.StdLib (>= 3.4.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.