开发者

How do I reference classes using IronPython?

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 refere开发者_如何学运维nced assemblies?


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

  • CLR Inside Out - IronPython
  • Introducing IronPython

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]()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜