pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/Taqiam/PythonNet.Helper

s" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/primer-bf8570e4081bd07e.css" /> GitHub - Taqiam/PythonNet.Helper: Bring Python to C# · GitHub
Skip to content
This repository was archived by the owner on Feb 1, 2026. It is now read-only.

Taqiam/PythonNet.Helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PythonNet.Helper

Bring Python to C# !!!

Nuget

This library is a help library for PythonNet, if you find any bugs, please report them. Also let me know if you have any comments

Install via NuGet

To install PythonNet.Helper, run the following command in the Package Manager Console :

PM> Install-Package PythonNet.Helper

Usage

To use this library, you must have .NET and Python installed

To start, make an instance of PyNet as below and give the Python DLL path

IPyNet pyNet = new PyNet(@"C:\Program Files\Python311\python311.dll");

Now you can use RunPython which has many overloads whose parameter list and input type are listed below

Name Type Description
pythonCode string Python code to be executed
parameters IDictionary<string, object> The list of input parameters in the form of a dictionary, which is the key of the variable name in Python
returnedVariableNames string[] The names of the variables that are supposed to be taken from the Python code
returnedVariableNames string[] The names of the variables that are supposed to be taken from the Python code
parameter (string key, object value) To pass a parameter instead of using a dictionary
returnedVariableName string To get just one return value instead of using an array

Samples

Run

pyNet.RunPython("print('Welcome To PythonNet.Helper')");

Run From File

You can give the address of the code file and use ReadFile to read the code as below

pyNet.RunPython("PythonFiles/HelloWorld.py".ReadFile());

By Parameters

  • Parameter
pyNet.RunPython(@$"print('Hello ' + name)", ("name", "Mohammad Taqi"));
  • Parameters
 pyNet.RunPython("print(fname + ' ' + lname)", new Dictionary<string, object>
{
    ["fname"] = "Mohammad Taqi",
    ["lname"] = "Nasiri"
});
  • Model parameter
public class UserModel
{
    public string Name { get; set; } = string.Empty;
    public string Family { get; set; } = string.Empty;
    public DateTime BirthDay { get; set; }
}
pyNet.RunPython("print(f'Name : {user.Name} | Family : {user.Family} | BirthDay : {user.BirthDay}')",("user",new UserModel()
{
    Name = "Mohammad Taqi",
    Family = "Nasiri",
    BirthDay = DateTime.Now
}));

By returned Variables

  • Without parameter
pyNet.RunPython("from datetime import date\n" + "today = date.today()", "today")
  • By parameter
int sumNumbers = Convert.ToInt32(pyNet.RunPython("sum = sum(nums)", ("nums", new List<int>() { 1, 5, 8, 7, 15, 20, 36 }), "sum").ToString())

You can also pass multiple parameters with a dictionary

About

Bring Python to C#

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy