IronPython 和实例化 COM 对象
我在 SharpDevelop 3.1 控制台窗口中使用 IronPython 2.0。 我正在尝试引用和使用 Redemption CDO 替换库。
该库的标准用法是实例化 RDOSession 对象,然后使用该对象上的方法来浏览 RDO 对象模型。
我已经注册了 Redemption COM dll 并从项目中引用了它,该项目为其创建了互操作程序集。 在 IronPython 控制台窗口中,我执行以下操作: 导入CLR clr.AddReferenceToFileAndPath(r'd:\SharpDevelop Projects\TestPython\TestPython\obj\Debug\Interop.Redemption.dll') import Redemption
到目前为止这有效。 下一步是获取 RDOSession 对象并实例化它。 如果它有效,我会想到这样做:
session = Redemption.RDOSession()
但是,这会产生错误: TypeError: 无法创建 RDOSession 实例
所以我的问题是(或者曾经是):如何实例化像 RDOSession 这样的对象?
然而,我只是回答了我自己的问题,试图解释它。 我将继续回答,因为尽管这样做似乎很愚蠢,但也许对其他人有用。
当我输入“session = Redemption.RDOSession()”行时,调用提示出现“RDOSession”以及其正下方的“RDOSessionClass”。 我不知道后者是如何生成的,但它听起来像是一个可实例化(如果这是一个词)对象。
>>>>> 会话 = Redemption.RDOSessionClass()
>>>>>
你瞧。 调用 Logon 方法对新会话对象来说非常有效。
感谢堆栈溢出!
I'm using IronPython 2.0 in a SharpDevelop 3.1 console window. I'm trying to reference and use the Redemption CDO replacement library.
The standard usage for the library is to instantiate an RDOSession object, then use the methods on that object to navigate through the RDO object model.
I've registered the Redemption COM dll and referenced it from a project, which created an interop assembly for it. In the IronPython console window, I then do the following:
import clr
clr.AddReferenceToFileAndPath(r'd:\SharpDevelop Projects\TestPython\TestPython\obj\Debug\Interop.Redemption.dll')
import Redemption
This works so far. The next step would be to get an RDOSession object and instantiate it. If it worked, this would be how I would think to do that:
session = Redemption.RDOSession()
However, this gives an error:
TypeError: Cannot create instances of RDOSession
So my question is (or was): how do I instantiate an object like RDOSession?
However, I just answered my own question in my attempt to explain it. I'll continue with the answer since despite the fact that it almost seems silly to do so, perhaps it will be useful to someone else.
When I went to type in the line "session = Redemption.RDOSession()", the calltip came up with "RDOSession" as well as "RDOSessionClass" right below it. I don't know how the latter was generated, but it sounded like an instantiable (if that's a word) object.
>>> session = Redemption.RDOSessionClass()
>>>
Lo and behold. Calling the Logon method worked like a champ on the new session object.
Thanks stackoverflow!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用:
You need to use: