SlideShare a Scribd company logo
1 of 25
INTRODUCTION TO
PYTHON.NET
ABOUT ME
โ€ข Stefan Schukat
โ€ข Software Architect, Physicist
โ€ข Different programming stages over the last 30 years
โ€ข Pascal, TCL/TK
โ€ข C/C++, ATL/MFC, COM, (VB)
โ€ข Python
โ€ข M
โ€ข C#
โ€ข Interest in software forensic and cross language techniques
โ€ข Twitter @tschodila
โ€ข https://www.xing.com/profile/Stefan_Schukat2
WHY CONSIDER PYTHON?
BASE OF PYTHON
โ€ข High level interpreted language
โ€ข Dynamic execution with no static typing
โ€ข Only few basic data types and programming elements are
defined
โ€ข Interpreter engine could be implemented on different
languages
โ€ข Extendable and embeddable
BASE PYTHON EXECUTION ARCHITECTURE
Python Code
Byte Code
Python API
Parse
Interpreter
Use
Extension
modul
Call
Native API
Call Call
C : C-Python
C# : IronPython
Java : Jython
Python : PyPy
PYTHON .NET
โ€ข Python Extension module for C-Python
โ€ข Access .NET runtime and libraries from Python scripting
โ€ข Combines history and amount of extensions from C-Python
with .NET
โ€ข Allows scripting access to .NET libraries in C-Python
โ€ข Allows embedding in console .NET Application to use C-Python
in .NET
โ€ข https://github.com/pythonnet/pythonnet
PYTHON.NET HISTORY
โ€ข Developer Brian Lloyd, Barton Cline, Christian Heimes
โ€ข Goal integrate .NET seamlessly in Python on Mono and Windows
โ€ข 1.0 for .NET 1.0 (2005), .NET 2.0 (2006)
โ€ข 2.0 Beta .NET 4.0 (2013) project abandoned
โ€ข Revived 2014 on GitHub
โ€ข Denis Akhiyarov, David Anthoff, Tony Roberts, Victor Uriarte
โ€ข 2.1 for .NET 4.x, Python 2.x, 3.x (2016)
โ€ข 2.2 for .NET 4.x, Added Python 3.6 (2017)
โ€ข .NET Core support is planned
PYTHON.NET ARCHITECTURE
clr.pyd
.NET
Assembly
Dynam
ic Load
PyInit_Clr
Python.Runtime.
dll
.NET Assembly
C-Export
for Python
Dll Import Python C-API
Wrapper Objects for Python Type APIs
Import Hook
Type Conversions
Reflection
โ€ฆ
PYTHON.NET RUNTIME OVERVIEW
DllImport("python.dll",
โ€ฆ)
DllImport("python.dll",
โ€ฆ)
โ€ฆ
Runtime
InitExt(โ€ฆ)
Engine PySequence
PyDict
ModuleObject
ClassObject
PropertyObject
โ€ฆ
Class Wrapper
for .NET Types
P-Invoke
Wrapper for C-
API
Class Wrapper
for Python
Types
โ€ฆ
Main entry point
Entry from Python Translation Python/NET Access Python-API
PYTHON .NET BASICS
โ€ข Uses reflection to initialize Python wrappers from .NET objects
โ€ข All public and protected members are available
โ€ข In case of name clash static method are preferred over instance methods
โ€ข Maps .NET namespaces to Python modules via Python import
hook
โ€ข Import statement prefers Python modules over .NET modules
โ€ข All variables in Python are reference types
โ€ข Any value type is always boxed in Python.NET
โ€ข Default mapping of data types between Python and BCL
TYPES MAPPING
.NET Type Python Type
String, Char unicode
Int16, UInt16, Int32, UInt32, Byte, SByte int
Int64, UInt64, UInt32 long (Py 2.x), int (Py 3.x)
Boolean bool
Single, Double float
IEnumerable list (sequence protocol)
null None
Decimal object
Struct decimal
ACCESSING NAMESPACE / ASSEMBLIES
>>> import clr # Initialize Runtime
>>> from System import String # Import Class from namespace
>>> from System.Collections import * # Import all from subnamespace
>>> clr.AddReference("System.Windows.Forms") # Add assembly
<System.Reflection.RuntimeAssembly object at 0x0000020A5FF06CF8>
>>> import System.Windows.Forms
>>> clr.AddReference("customsigned, Version=1.5.0.0, Culture=neutral,
PublicKeyToken=12345678babeaffe")
โ€ข Search order
โ€ข Standard Python modules
โ€ข Loaded Assemblies
โ€ข Python path for .NET assemblies (Assembly.LoadFrom)
โ€ข .NET Loader (Assembly.Load)
STRUCTS, METHODS, PROPERTIES
>>> import System.Drawing import Point # Import struct
>>> p = Point(5, 5) # Instantiate struct
>>> p.X # Access property
5
>>> from System import Math # Import static class
>>> Math.Abs(-212) # Access Method
212
GENERICS AND OVERLOADS
>>> from System import String, Char, Int32 # Import used types
>>> s = String.Overloads[Char, Int32]("A", 10) # Use overloaded constructor
>>> s # display class
<System.String object at 0x0000020A5FF64908>
>>> print(s) # Use ToString method
AAAAAAAA
>>> from System.Collections.Generic import Dictionary # Import used types
>>> d = Dictionary[String, String]() # Use generic constructor
>>> d2 = Dictionary[str, str]() # Use auto mapped types
>>> print(d) # Use ToString method
System.Collections.Generic.Dictionary`2[System.String,System.String]
INDEXERS, ARRAYS
>>> from System.Collections.Generic import Dictionary as d
>>> jagged = d[str, d[str, int]]() # Create dict of dicts
>>> jagged["a"] = d[str, int]()
>>> jagged["a"]["b"] = 10
>>> jagged["a"]["b"]
10
>>> from System import Array
>>> a = Array[int]([2,2])
>>> a
<System.Int32[] object at 0x0000020A5FF838D0>
>>> a[0] # Multidimensional a[1,1]
2
DELEGATES AND EVENTS
>>> from System import AssemblyLoadEventHandler, AppDomain
>>> def LoadHandler(source, args):
... print("Python called for {0}".format(args.LoadAssembly.FullName))
...
>>> e = AssemblyLoadEventHandler(LoadHandler) # Create delegate
>>> AppDomain.CurrentDomain.AssemblyLoad += e # Register delegate
>>> clr.AddReference("System.Windows.Forms") # Add assembly
Python called for Accessibility, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a
Python called for System.Windows.Forms, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
Python called for System.Drawing, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a
>>> AppDomain.CurrentDomain.AssemblyLoad -= e # Unregister delegate
EXCEPTIONS
>>> from System import NullReferenceException # Use BCL exception
>>> try:
... raise NullReferenceException("Empty test")
... except NullReferenceException as e:
... print(e.Message)
... print(e.Source)
Empty test
None
COLLECTIONS
>>> from System import AppDomain # Use class which supports IEnumerable
>>> for item in AppDomain.CurrentDomain.GetAssemblies():
... print(item.FullName)
...
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
clrmodule, Version=2.3.0.0, Culture=neutral, PublicKeyToken=null
Python.Runtime, Version=2.4.0.0, Culture=neutral, PublicKeyToken=null
System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
__CodeGenerator_Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
e__NativeCall_Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
โ€ฆ
UI PYTHON .NET
โ€ข Simple way
โ€ข Write .NET Class Assembly with UI (Winforms or WPF)
โ€ข Export functions to be used
โ€ข Hard way
โ€ข Rewrite generated code via Python.NET
UI WINFORMS C# CODE
using System;
using System.Windows.Forms;
namespace UILibrary
{
public partial class MainForm : Form
{
public Action PythonCallBack { get; set; }
public MainForm()
{
InitializeComponent();
}
private void ButtonCallPython_Click(object sender, System.EventArgs e)
=> this.PythonCallBack?.Invoke();
}
}
UI WINFORMS PYTHON CODE IN UI
APPLICATIONimport clr
clr.AddReference("UILibrary")
import UILibrary
from System import Action
def CallBack():
"""Button click event handler"""
print("Button clicked!")
MainForm = UILibrary.MainForm()
MainForm.PythonCallBack = Action(CallBack)
MainForm.ShowDialog()
UI WINFORMS PYTHON CODE IN CONSOLE
APPimport clr
clr.AddReference("System.Windows.Forms")
clr.AddReference("UILibrary")
import System.Windows.Forms as WinForms
import UILibrary
from System import Action
class WinFormsTest:
def __init__(self):
self.MainForm = UILibrary.MainForm()
self.MainForm.PythonCallBack = Action(self.CallBack)
app = WinForms.Application
app.Run(self.MainForm)
def CallBack(self):
"""Button click event handler"""
print("Button clicked!")
if __name__ == '__main__':
ui = WinFormsTest()
WINFORMS PURE PYTHON
self.buttonCallPython.Click +=
System.EventHandler(self.ButtonCallPython_Click)
self.AutoScaleDimensions =
System.Drawing.SizeF(6.0, 13.0)
self.AutoScaleMode =
System.Windows.Forms.AutoScaleMode.Font
self.ClientSize = System.Drawing.Size(245, 44)
self.Controls.Add(self.buttonCallPython)
self.MaximizeBox = False
self.MinimizeBox = False
self.Name = "MainForm"
self.Text = "TestWinforms"
self.ResumeLayout(False)
if __name__ == "__main__":
m = MainForm()
m.ShowDialog()
import clr
import System
import System.Windows.Forms
import System.Drawing
class MainForm(System.Windows.Forms.Form):
def __init__(self):
self.InitializeComponent()
def ButtonCallPython_Click(self, source, args):
print("Button clicked")
def InitializeComponent(self):
self.buttonCallPython =
System.Windows.Forms.Button()
self.SuspendLayout()
self.buttonCallPython.Location =
System.Drawing.Point(12, 12)
self.buttonCallPython.Name = "buttonCallPython"
self.buttonCallPython.Size =
System.Drawing.Size(75, 23)
self.buttonCallPython.TabIndex = 0
self.buttonCallPython.Text = "Call Python"
self.buttonCallPython.UseVisualStyleBackColor =
True
FURTHER USE CASES
โ€ข Automatic conversion of Python dictionary as .NET dictionary
โ€ข Usage of .NET enums as Python enums
โ€ข Routing of win32com.client COM objects as __ComObject
THANK YOU!
???????

More Related Content

What's hot

DSLs in JavaScript
DSLs in JavaScriptDSLs in JavaScript
DSLs in JavaScriptelliando dias
ย 
Bร i 3: Lแบญp trรฌnh giao diแป‡n ฤ‘iแปu khiแปƒn & Xแปญ lรฝ sแปฑ kiแป‡n - Lแบญp trรฌnh winform - G...
Bร i 3: Lแบญp trรฌnh giao diแป‡n ฤ‘iแปu khiแปƒn & Xแปญ lรฝ sแปฑ kiแป‡n - Lแบญp trรฌnh winform - G...Bร i 3: Lแบญp trรฌnh giao diแป‡n ฤ‘iแปu khiแปƒn & Xแปญ lรฝ sแปฑ kiแป‡n - Lแบญp trรฌnh winform - G...
Bร i 3: Lแบญp trรฌnh giao diแป‡n ฤ‘iแปu khiแปƒn & Xแปญ lรฝ sแปฑ kiแป‡n - Lแบญp trรฌnh winform - G...MasterCode.vn
ย 
Socket programming using C
Socket programming using CSocket programming using C
Socket programming using CAjit Nayak
ย 
Python Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | EdurekaPython Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | EdurekaEdureka!
ย 
Python Programming - VI. Classes and Objects
Python Programming - VI. Classes and ObjectsPython Programming - VI. Classes and Objects
Python Programming - VI. Classes and ObjectsRanel Padon
ย 
Basic concepts for python web development
Basic concepts for python web developmentBasic concepts for python web development
Basic concepts for python web developmentNexSoftsys
ย 
Sap script system_symbol
Sap script system_symbolSap script system_symbol
Sap script system_symbolmoderngladiator
ย 
PyTorch under the hood
PyTorch under the hoodPyTorch under the hood
PyTorch under the hoodChristian Perone
ย 
Chapter 2 Decision Making (Python Programming Lecture)
Chapter 2 Decision Making (Python Programming Lecture)Chapter 2 Decision Making (Python Programming Lecture)
Chapter 2 Decision Making (Python Programming Lecture)IoT Code Lab
ย 
An Actor Model in Go
An Actor Model in GoAn Actor Model in Go
An Actor Model in GoWeaveworks
ย 
Les fonctions lambdas en C++11 et C++14
Les fonctions lambdas en C++11 et C++14Les fonctions lambdas en C++11 et C++14
Les fonctions lambdas en C++11 et C++14Aurรฉlien Regat-Barrel
ย 
Programming with Python
Programming with PythonProgramming with Python
Programming with PythonRasan Samarasinghe
ย 
What is Python? | Edureka
What is Python? | EdurekaWhat is Python? | Edureka
What is Python? | EdurekaEdureka!
ย 
Using Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyLaunchAny
ย 
Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3Chariza Pladin
ย 
Regular Expressions Cheat Sheet
Regular Expressions Cheat SheetRegular Expressions Cheat Sheet
Regular Expressions Cheat SheetAkash Bisariya
ย 
Introduction to Python - Part Three
Introduction to Python - Part ThreeIntroduction to Python - Part Three
Introduction to Python - Part Threeamiable_indian
ย 
V8 javascript engine for ใƒ•ใƒญใƒณใƒˆใ‚จใƒณใƒ‰ใƒ‡ใƒ™ใƒญใƒƒใƒ‘ใƒผ
V8 javascript engine for ใƒ•ใƒญใƒณใƒˆใ‚จใƒณใƒ‰ใƒ‡ใƒ™ใƒญใƒƒใƒ‘ใƒผV8 javascript engine for ใƒ•ใƒญใƒณใƒˆใ‚จใƒณใƒ‰ใƒ‡ใƒ™ใƒญใƒƒใƒ‘ใƒผ
V8 javascript engine for ใƒ•ใƒญใƒณใƒˆใ‚จใƒณใƒ‰ใƒ‡ใƒ™ใƒญใƒƒใƒ‘ใƒผTaketoshi ้’้‡Žๅฅๅˆฉ
ย 
Python, the Language of Science and Engineering for Engineers
Python, the Language of Science and Engineering for EngineersPython, the Language of Science and Engineering for Engineers
Python, the Language of Science and Engineering for EngineersBoey Pak Cheong
ย 
Design Pattern - Nhแปฏng cรดng thแปฉc vร ng trong thiแบฟt kแบฟ
Design Pattern - Nhแปฏng cรดng thแปฉc vร ng trong thiแบฟt kแบฟDesign Pattern - Nhแปฏng cรดng thแปฉc vร ng trong thiแบฟt kแบฟ
Design Pattern - Nhแปฏng cรดng thแปฉc vร ng trong thiแบฟt kแบฟNhแบญt Nguyแป…n Khแบฏc
ย 

What's hot (20)

DSLs in JavaScript
DSLs in JavaScriptDSLs in JavaScript
DSLs in JavaScript
ย 
Bร i 3: Lแบญp trรฌnh giao diแป‡n ฤ‘iแปu khiแปƒn & Xแปญ lรฝ sแปฑ kiแป‡n - Lแบญp trรฌnh winform - G...
Bร i 3: Lแบญp trรฌnh giao diแป‡n ฤ‘iแปu khiแปƒn & Xแปญ lรฝ sแปฑ kiแป‡n - Lแบญp trรฌnh winform - G...Bร i 3: Lแบญp trรฌnh giao diแป‡n ฤ‘iแปu khiแปƒn & Xแปญ lรฝ sแปฑ kiแป‡n - Lแบญp trรฌnh winform - G...
Bร i 3: Lแบญp trรฌnh giao diแป‡n ฤ‘iแปu khiแปƒn & Xแปญ lรฝ sแปฑ kiแป‡n - Lแบญp trรฌnh winform - G...
ย 
Socket programming using C
Socket programming using CSocket programming using C
Socket programming using C
ย 
Python Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | EdurekaPython Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | Edureka
ย 
Python Programming - VI. Classes and Objects
Python Programming - VI. Classes and ObjectsPython Programming - VI. Classes and Objects
Python Programming - VI. Classes and Objects
ย 
Basic concepts for python web development
Basic concepts for python web developmentBasic concepts for python web development
Basic concepts for python web development
ย 
Sap script system_symbol
Sap script system_symbolSap script system_symbol
Sap script system_symbol
ย 
PyTorch under the hood
PyTorch under the hoodPyTorch under the hood
PyTorch under the hood
ย 
Chapter 2 Decision Making (Python Programming Lecture)
Chapter 2 Decision Making (Python Programming Lecture)Chapter 2 Decision Making (Python Programming Lecture)
Chapter 2 Decision Making (Python Programming Lecture)
ย 
An Actor Model in Go
An Actor Model in GoAn Actor Model in Go
An Actor Model in Go
ย 
Les fonctions lambdas en C++11 et C++14
Les fonctions lambdas en C++11 et C++14Les fonctions lambdas en C++11 et C++14
Les fonctions lambdas en C++11 et C++14
ย 
Programming with Python
Programming with PythonProgramming with Python
Programming with Python
ย 
What is Python? | Edureka
What is Python? | EdurekaWhat is Python? | Edureka
What is Python? | Edureka
ย 
Using Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in Ruby
ย 
Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3
ย 
Regular Expressions Cheat Sheet
Regular Expressions Cheat SheetRegular Expressions Cheat Sheet
Regular Expressions Cheat Sheet
ย 
Introduction to Python - Part Three
Introduction to Python - Part ThreeIntroduction to Python - Part Three
Introduction to Python - Part Three
ย 
V8 javascript engine for ใƒ•ใƒญใƒณใƒˆใ‚จใƒณใƒ‰ใƒ‡ใƒ™ใƒญใƒƒใƒ‘ใƒผ
V8 javascript engine for ใƒ•ใƒญใƒณใƒˆใ‚จใƒณใƒ‰ใƒ‡ใƒ™ใƒญใƒƒใƒ‘ใƒผV8 javascript engine for ใƒ•ใƒญใƒณใƒˆใ‚จใƒณใƒ‰ใƒ‡ใƒ™ใƒญใƒƒใƒ‘ใƒผ
V8 javascript engine for ใƒ•ใƒญใƒณใƒˆใ‚จใƒณใƒ‰ใƒ‡ใƒ™ใƒญใƒƒใƒ‘ใƒผ
ย 
Python, the Language of Science and Engineering for Engineers
Python, the Language of Science and Engineering for EngineersPython, the Language of Science and Engineering for Engineers
Python, the Language of Science and Engineering for Engineers
ย 
Design Pattern - Nhแปฏng cรดng thแปฉc vร ng trong thiแบฟt kแบฟ
Design Pattern - Nhแปฏng cรดng thแปฉc vร ng trong thiแบฟt kแบฟDesign Pattern - Nhแปฏng cรดng thแปฉc vร ng trong thiแบฟt kแบฟ
Design Pattern - Nhแปฏng cรดng thแปฉc vร ng trong thiแบฟt kแบฟ
ย 

Similar to Introduction to Python.Net

Introduction to python.pptx
Introduction to python.pptxIntroduction to python.pptx
Introduction to python.pptxpcjoshi02
ย 
Programming using c++ tool
Programming using c++ toolProgramming using c++ tool
Programming using c++ toolAbdullah Jan
ย 
Lecture1_introduction to python.pptx
Lecture1_introduction to python.pptxLecture1_introduction to python.pptx
Lecture1_introduction to python.pptxMohammedAlYemeni1
ย 
Iron python
Iron pythonIron python
Iron pythonGeorgeIshak
ย 
Pemrograman Python untuk Pemula
Pemrograman Python untuk PemulaPemrograman Python untuk Pemula
Pemrograman Python untuk PemulaOon Arfiandwi
ย 
Python Basis Tutorial
Python Basis TutorialPython Basis Tutorial
Python Basis Tutorialmd sathees
ย 
Pythonpresent
PythonpresentPythonpresent
PythonpresentChui-Wen Chiu
ย 
Introduction to cython
Introduction to cythonIntroduction to cython
Introduction to cythonJohn(Qiang) Zhang
ย 
Preprocessor , IOSTREAM Library,IOMANIP Library
Preprocessor , IOSTREAM Library,IOMANIP LibraryPreprocessor , IOSTREAM Library,IOMANIP Library
Preprocessor , IOSTREAM Library,IOMANIP LibraryMeghaj Mallick
ย 
Anish PPT-GIT.pptx
Anish PPT-GIT.pptxAnish PPT-GIT.pptx
Anish PPT-GIT.pptxMOHAMMADANISH12
ย 
Format of first slide for main PPT-GIT.pptx
Format of first slide for main PPT-GIT.pptxFormat of first slide for main PPT-GIT.pptx
Format of first slide for main PPT-GIT.pptxMOHAMMADANISH12
ย 
Python programming workshop session 1
Python programming workshop session 1Python programming workshop session 1
Python programming workshop session 1Abdul Haseeb
ย 
web programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Malothweb programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh MalothBhavsingh Maloth
ย 
Revision of the basics of python1 (1).pdf
Revision of the basics of python1 (1).pdfRevision of the basics of python1 (1).pdf
Revision of the basics of python1 (1).pdfoptimusnotch44
ย 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Edureka!
ย 
Introduction to Python.pdf
Introduction to Python.pdfIntroduction to Python.pdf
Introduction to Python.pdfRahul Mogal
ย 
PYTHON PROGRAMMING NOTES RKREDDY.pdf
PYTHON PROGRAMMING NOTES RKREDDY.pdfPYTHON PROGRAMMING NOTES RKREDDY.pdf
PYTHON PROGRAMMING NOTES RKREDDY.pdfRamakrishna Reddy Bijjam
ย 

Similar to Introduction to Python.Net (20)

Introduction to python.pptx
Introduction to python.pptxIntroduction to python.pptx
Introduction to python.pptx
ย 
Programming using c++ tool
Programming using c++ toolProgramming using c++ tool
Programming using c++ tool
ย 
Lecture1_introduction to python.pptx
Lecture1_introduction to python.pptxLecture1_introduction to python.pptx
Lecture1_introduction to python.pptx
ย 
Iron python
Iron pythonIron python
Iron python
ย 
Pemrograman Python untuk Pemula
Pemrograman Python untuk PemulaPemrograman Python untuk Pemula
Pemrograman Python untuk Pemula
ย 
Python Basis Tutorial
Python Basis TutorialPython Basis Tutorial
Python Basis Tutorial
ย 
Pythonpresent
PythonpresentPythonpresent
Pythonpresent
ย 
Introduction to cython
Introduction to cythonIntroduction to cython
Introduction to cython
ย 
Preprocessor , IOSTREAM Library,IOMANIP Library
Preprocessor , IOSTREAM Library,IOMANIP LibraryPreprocessor , IOSTREAM Library,IOMANIP Library
Preprocessor , IOSTREAM Library,IOMANIP Library
ย 
Anish PPT-GIT.pptx
Anish PPT-GIT.pptxAnish PPT-GIT.pptx
Anish PPT-GIT.pptx
ย 
Format of first slide for main PPT-GIT.pptx
Format of first slide for main PPT-GIT.pptxFormat of first slide for main PPT-GIT.pptx
Format of first slide for main PPT-GIT.pptx
ย 
PPT-GIT.pptx
PPT-GIT.pptxPPT-GIT.pptx
PPT-GIT.pptx
ย 
Python programming workshop session 1
Python programming workshop session 1Python programming workshop session 1
Python programming workshop session 1
ย 
web programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Malothweb programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Maloth
ย 
05 python.pdf
05 python.pdf05 python.pdf
05 python.pdf
ย 
Revision of the basics of python1 (1).pdf
Revision of the basics of python1 (1).pdfRevision of the basics of python1 (1).pdf
Revision of the basics of python1 (1).pdf
ย 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
ย 
Introduction to Python.pdf
Introduction to Python.pdfIntroduction to Python.pdf
Introduction to Python.pdf
ย 
Python ppt
Python pptPython ppt
Python ppt
ย 
PYTHON PROGRAMMING NOTES RKREDDY.pdf
PYTHON PROGRAMMING NOTES RKREDDY.pdfPYTHON PROGRAMMING NOTES RKREDDY.pdf
PYTHON PROGRAMMING NOTES RKREDDY.pdf
ย 

Recently uploaded

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female serviceCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
ย 
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE9953056974 Low Rate Call Girls In Saket, Delhi NCR
ย 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
ย 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธanilsa9823
ย 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
ย 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
ย 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfWilly Marroquin (WillyDevNET)
ย 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
ย 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
ย 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
ย 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
ย 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
ย 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
ย 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
ย 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
ย 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
ย 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
ย 

Recently uploaded (20)

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female serviceCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
ย 
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
ย 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
ย 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธ
ย 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
ย 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
ย 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
ย 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
ย 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
ย 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
ย 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
ย 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
ย 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
ย 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
ย 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
ย 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
ย 
Vip Call Girls Noida โžก๏ธ Delhi โžก๏ธ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida โžก๏ธ Delhi โžก๏ธ 9999965857 No Advance 24HRS LiveVip Call Girls Noida โžก๏ธ Delhi โžก๏ธ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida โžก๏ธ Delhi โžก๏ธ 9999965857 No Advance 24HRS Live
ย 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
ย 

Introduction to Python.Net

  • 2. ABOUT ME โ€ข Stefan Schukat โ€ข Software Architect, Physicist โ€ข Different programming stages over the last 30 years โ€ข Pascal, TCL/TK โ€ข C/C++, ATL/MFC, COM, (VB) โ€ข Python โ€ข M โ€ข C# โ€ข Interest in software forensic and cross language techniques โ€ข Twitter @tschodila โ€ข https://www.xing.com/profile/Stefan_Schukat2
  • 4. BASE OF PYTHON โ€ข High level interpreted language โ€ข Dynamic execution with no static typing โ€ข Only few basic data types and programming elements are defined โ€ข Interpreter engine could be implemented on different languages โ€ข Extendable and embeddable
  • 5. BASE PYTHON EXECUTION ARCHITECTURE Python Code Byte Code Python API Parse Interpreter Use Extension modul Call Native API Call Call C : C-Python C# : IronPython Java : Jython Python : PyPy
  • 6. PYTHON .NET โ€ข Python Extension module for C-Python โ€ข Access .NET runtime and libraries from Python scripting โ€ข Combines history and amount of extensions from C-Python with .NET โ€ข Allows scripting access to .NET libraries in C-Python โ€ข Allows embedding in console .NET Application to use C-Python in .NET โ€ข https://github.com/pythonnet/pythonnet
  • 7. PYTHON.NET HISTORY โ€ข Developer Brian Lloyd, Barton Cline, Christian Heimes โ€ข Goal integrate .NET seamlessly in Python on Mono and Windows โ€ข 1.0 for .NET 1.0 (2005), .NET 2.0 (2006) โ€ข 2.0 Beta .NET 4.0 (2013) project abandoned โ€ข Revived 2014 on GitHub โ€ข Denis Akhiyarov, David Anthoff, Tony Roberts, Victor Uriarte โ€ข 2.1 for .NET 4.x, Python 2.x, 3.x (2016) โ€ข 2.2 for .NET 4.x, Added Python 3.6 (2017) โ€ข .NET Core support is planned
  • 8. PYTHON.NET ARCHITECTURE clr.pyd .NET Assembly Dynam ic Load PyInit_Clr Python.Runtime. dll .NET Assembly C-Export for Python Dll Import Python C-API Wrapper Objects for Python Type APIs Import Hook Type Conversions Reflection โ€ฆ
  • 9. PYTHON.NET RUNTIME OVERVIEW DllImport("python.dll", โ€ฆ) DllImport("python.dll", โ€ฆ) โ€ฆ Runtime InitExt(โ€ฆ) Engine PySequence PyDict ModuleObject ClassObject PropertyObject โ€ฆ Class Wrapper for .NET Types P-Invoke Wrapper for C- API Class Wrapper for Python Types โ€ฆ Main entry point Entry from Python Translation Python/NET Access Python-API
  • 10. PYTHON .NET BASICS โ€ข Uses reflection to initialize Python wrappers from .NET objects โ€ข All public and protected members are available โ€ข In case of name clash static method are preferred over instance methods โ€ข Maps .NET namespaces to Python modules via Python import hook โ€ข Import statement prefers Python modules over .NET modules โ€ข All variables in Python are reference types โ€ข Any value type is always boxed in Python.NET โ€ข Default mapping of data types between Python and BCL
  • 11. TYPES MAPPING .NET Type Python Type String, Char unicode Int16, UInt16, Int32, UInt32, Byte, SByte int Int64, UInt64, UInt32 long (Py 2.x), int (Py 3.x) Boolean bool Single, Double float IEnumerable list (sequence protocol) null None Decimal object Struct decimal
  • 12. ACCESSING NAMESPACE / ASSEMBLIES >>> import clr # Initialize Runtime >>> from System import String # Import Class from namespace >>> from System.Collections import * # Import all from subnamespace >>> clr.AddReference("System.Windows.Forms") # Add assembly <System.Reflection.RuntimeAssembly object at 0x0000020A5FF06CF8> >>> import System.Windows.Forms >>> clr.AddReference("customsigned, Version=1.5.0.0, Culture=neutral, PublicKeyToken=12345678babeaffe") โ€ข Search order โ€ข Standard Python modules โ€ข Loaded Assemblies โ€ข Python path for .NET assemblies (Assembly.LoadFrom) โ€ข .NET Loader (Assembly.Load)
  • 13. STRUCTS, METHODS, PROPERTIES >>> import System.Drawing import Point # Import struct >>> p = Point(5, 5) # Instantiate struct >>> p.X # Access property 5 >>> from System import Math # Import static class >>> Math.Abs(-212) # Access Method 212
  • 14. GENERICS AND OVERLOADS >>> from System import String, Char, Int32 # Import used types >>> s = String.Overloads[Char, Int32]("A", 10) # Use overloaded constructor >>> s # display class <System.String object at 0x0000020A5FF64908> >>> print(s) # Use ToString method AAAAAAAA >>> from System.Collections.Generic import Dictionary # Import used types >>> d = Dictionary[String, String]() # Use generic constructor >>> d2 = Dictionary[str, str]() # Use auto mapped types >>> print(d) # Use ToString method System.Collections.Generic.Dictionary`2[System.String,System.String]
  • 15. INDEXERS, ARRAYS >>> from System.Collections.Generic import Dictionary as d >>> jagged = d[str, d[str, int]]() # Create dict of dicts >>> jagged["a"] = d[str, int]() >>> jagged["a"]["b"] = 10 >>> jagged["a"]["b"] 10 >>> from System import Array >>> a = Array[int]([2,2]) >>> a <System.Int32[] object at 0x0000020A5FF838D0> >>> a[0] # Multidimensional a[1,1] 2
  • 16. DELEGATES AND EVENTS >>> from System import AssemblyLoadEventHandler, AppDomain >>> def LoadHandler(source, args): ... print("Python called for {0}".format(args.LoadAssembly.FullName)) ... >>> e = AssemblyLoadEventHandler(LoadHandler) # Create delegate >>> AppDomain.CurrentDomain.AssemblyLoad += e # Register delegate >>> clr.AddReference("System.Windows.Forms") # Add assembly Python called for Accessibility, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a Python called for System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Python called for System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a >>> AppDomain.CurrentDomain.AssemblyLoad -= e # Unregister delegate
  • 17. EXCEPTIONS >>> from System import NullReferenceException # Use BCL exception >>> try: ... raise NullReferenceException("Empty test") ... except NullReferenceException as e: ... print(e.Message) ... print(e.Source) Empty test None
  • 18. COLLECTIONS >>> from System import AppDomain # Use class which supports IEnumerable >>> for item in AppDomain.CurrentDomain.GetAssemblies(): ... print(item.FullName) ... mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 clrmodule, Version=2.3.0.0, Culture=neutral, PublicKeyToken=null Python.Runtime, Version=2.4.0.0, Culture=neutral, PublicKeyToken=null System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 __CodeGenerator_Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null e__NativeCall_Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a โ€ฆ
  • 19. UI PYTHON .NET โ€ข Simple way โ€ข Write .NET Class Assembly with UI (Winforms or WPF) โ€ข Export functions to be used โ€ข Hard way โ€ข Rewrite generated code via Python.NET
  • 20. UI WINFORMS C# CODE using System; using System.Windows.Forms; namespace UILibrary { public partial class MainForm : Form { public Action PythonCallBack { get; set; } public MainForm() { InitializeComponent(); } private void ButtonCallPython_Click(object sender, System.EventArgs e) => this.PythonCallBack?.Invoke(); } }
  • 21. UI WINFORMS PYTHON CODE IN UI APPLICATIONimport clr clr.AddReference("UILibrary") import UILibrary from System import Action def CallBack(): """Button click event handler""" print("Button clicked!") MainForm = UILibrary.MainForm() MainForm.PythonCallBack = Action(CallBack) MainForm.ShowDialog()
  • 22. UI WINFORMS PYTHON CODE IN CONSOLE APPimport clr clr.AddReference("System.Windows.Forms") clr.AddReference("UILibrary") import System.Windows.Forms as WinForms import UILibrary from System import Action class WinFormsTest: def __init__(self): self.MainForm = UILibrary.MainForm() self.MainForm.PythonCallBack = Action(self.CallBack) app = WinForms.Application app.Run(self.MainForm) def CallBack(self): """Button click event handler""" print("Button clicked!") if __name__ == '__main__': ui = WinFormsTest()
  • 23. WINFORMS PURE PYTHON self.buttonCallPython.Click += System.EventHandler(self.ButtonCallPython_Click) self.AutoScaleDimensions = System.Drawing.SizeF(6.0, 13.0) self.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font self.ClientSize = System.Drawing.Size(245, 44) self.Controls.Add(self.buttonCallPython) self.MaximizeBox = False self.MinimizeBox = False self.Name = "MainForm" self.Text = "TestWinforms" self.ResumeLayout(False) if __name__ == "__main__": m = MainForm() m.ShowDialog() import clr import System import System.Windows.Forms import System.Drawing class MainForm(System.Windows.Forms.Form): def __init__(self): self.InitializeComponent() def ButtonCallPython_Click(self, source, args): print("Button clicked") def InitializeComponent(self): self.buttonCallPython = System.Windows.Forms.Button() self.SuspendLayout() self.buttonCallPython.Location = System.Drawing.Point(12, 12) self.buttonCallPython.Name = "buttonCallPython" self.buttonCallPython.Size = System.Drawing.Size(75, 23) self.buttonCallPython.TabIndex = 0 self.buttonCallPython.Text = "Call Python" self.buttonCallPython.UseVisualStyleBackColor = True
  • 24. FURTHER USE CASES โ€ข Automatic conversion of Python dictionary as .NET dictionary โ€ข Usage of .NET enums as Python enums โ€ข Routing of win32com.client COM objects as __ComObject

Editor's Notes

  1. [DllExport("PyInit_clr", CallingConvention.StdCall)] public static IntPtr PyInit_clr()
  2. [DllExport("PyInit_clr", CallingConvention.StdCall)] public static IntPtr PyInit_clr()
  3. Search sequence with given name Python path + name + (.dll|.exe) (Assembly.LoadFrom) .NET loader (Assembly.Load)
  4. Any error in a delegate is swallowed
  5. Any error in a delegate is swallowed
  6. Any error in a delegate is swallowed
  7. Any error in a delegate is swallowed
  8. Any error in a delegate is swallowed
  9. Any error in a delegate is swallowed
  10. Any error in a delegate is swallowed