Question

I want to use IronPython as a simple test harness for a .net application. I have created a project in Visual Studio 2008 and have an empty python source file. I have added my assemblies to the project in Visual Studio. I am familiar with general python programming.

How do I import and use classes from my referenced assemblies?

Was it helpful?

Solution

It should just be

import [namespace]

for common .NET libraries and namespaces, such as System

to use additional assemblies, first need to import clr then add a reference to additional assemblies

import clr
clr.AddReference("System.Xml")
from System.Xml import *

Take a look at

Also, have a look at where you installed IronPython. There is a lot of detail in the Tutorial.htm that can be found in \IronPython 2.0.1\Tutorial\Tutorial.htm

You generally create instance of classes like so

from System.Collections import *
# create an instance of Hashtable
h = Hashtable() 

from System.Collections.Generic import *
# create an instance of List<string>
l = List[str]()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top