views:

71

answers:

1

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?

+2  A: 

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]()
Russ Cam
What about adding custom assemblies? I am having some trouble getting those to load.
Russell
Check out http://blogs.msdn.com/haibo_luo/archive/2007/09/25/5130072.aspx and http://stackoverflow.com/questions/1200182/how-to-use-a-c-dll-in-ironpython and http://stackoverflow.com/questions/1579922/issue-with-using-a-net-class-in-ironpython
Tom E