IronPython: Grab the .NET Type

After loading the assembly by clr.AddReference and then import namespace, we are ready to take hold of types and down-level namespaces using “attribute references”. >>> import System>>> System.DateTime                    # type<type ‘DateTime’>>>> System.Diagnostics                 # still namespace<module ‘Diagnostics’ (CLS module, 2 assemblies loaded)>>>> System.Diagnostics.Debug           # type again<type ‘Debug’>>>> System.Diagnostics.CodeAnalysis    # namespace again<module ‘CodeAnalysis’ (CLS module from mscorlib,…


IronPython: clr.AddReference

In order to interop with .NET libraries, we need first load in the assemblies we want to play with. The family of AddReference methods in the clr module serves the purpose. clr.AddReference clr.AddReferenceByName clr.AddReferenceByPartialName clr.AddReferenceToFile clr.AddReferenceToFileAndPath clr.AddReference accepts System.Reflection.Assembly objects and/or assembly names. The typical usage looks like: asm = … # any approach of…

5

IronPython: import clr

clr is an IronPython built-in module, which provides some functionalities in order to interop with .NET. When writing “import clr” in a python module, it means you intend to leverage the .NET libraries. One classical example is python string’s methods. In IronPython, python type str is implemented by the .NET type System.String. We can call…