[IronPython] Call methods from Python-Script

Dino Viehland dinov at microsoft.com
Wed Aug 26 18:46:21 CEST 2009

Is CClassName a public type?  It'll need to both have public members and also be public its self.

If that's not the problem I'm having trouble understanding exactly what's going on.  Is "return class.doSomething(parameter)" supposedly Python code?  Or are you doing this from C#?  "class" is a keyword in Python so I don't see how it's Python code.

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Eichhorn, Georg
Sent: Tuesday, August 25, 2009 11:00 PM
To: users at lists.ironpython.com
Subject: [IronPython] Call methods from Python-Script


I have implemented some piece of code that should execute a python-script. In this script I want to call a c#-function.
First, I Generate a module (context to work in):

 _scriptRuntime.ScriptScope.SetVariable("class", this); ('this' is CClassName')

Then I get the class:

PythonType pType = _scriptRuntime.ScriptScope.GetVariable("CClassName") as PythonType;

Create an instance of the object

_Class = _scriptRuntime.ScriptScope.Engine.Operations.CreateInstance(pType, new object[] { });

[...] (do some other tings)

>From the python script, I want to call the function:

return class.doSomething(parameter)

The code throws an exception:

'CClassName' object has no attribute 'doSomething'.

What am I making wrong? CClassName has a public method doSomething()

Thanks for U're help.

Georg Eichhorn

The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20090826/1c66c1b8/attachment.html>

More information about the Ironpython-users mailing list