当我在研究这个问题时,我偶然发现了我认为是答案的答案(这只是一个尝试和错误,所以如果我错了,我很乐意被纠正!)在
Python中的import语句更类似于C中的using 语句。您仍然需要加载相关的.dll程序集。C在编译时通过使用引用来实现这一点;IronPython默认包含标准的CLR引用,这就是为什么import System.Xml
但是,如果要加载默认情况下未包含在IronPython中的.dll,则必须使用clr.AddReference("myAssembly.dll")和,然后使用import语句导入模块。在
例如:import clr
clr.AddReferenceToFileAndPath(r"..\lib\umbraco.dll")
import umbraco
umbraco模块现在可由IronPython访问
注意:visualstudio插件“Python工具”允许您添加对Python项目的引用,但是使用引用仍然需要上述步骤。在Visual Studio projects support adding references to projects and extensions. Typically they indicate dependencies between projects and are used to provide IntelliSense at design time or linking at compile time. Python Tools for Visual Studio also uses references in a similar fashion, but due to the dynamic nature of Python they are primarly used at design time to provide improved IntelliSense.