[Python.NET] exposing modules
Brian Lloyd
Brian.Lloyd at revolution.com
Fri Jun 9 15:54:12 CEST 2006
Haran - you can't expose a 'module' (in the Python sense), but
you can easily do what you trying to do.
The usual pattern for this would be stow away a reference to your
application object in a static where the Python code can then get
it. Assuming you have an assembly 'my.app', this would look like:
namespace my.app {
public class MyApp {
public static MyApp theapp;
public MyApp() {
// do initialization
theapp = this;
}
}
}
Now from Python you can do the following:
from my.app import MyApp
app = MyApp.theapp
hope this helps,
-Brian
> -----Original Message-----
> From: pythondotnet-bounces at python.org
> [mailto:pythondotnet-bounces at python.org] On Behalf Of Haran Shivanan
> Sent: Thursday, June 08, 2006 11:27 PM
> To: pythondotnet at python.org
> Subject: [Python.NET] exposing modules
>
> Hi,
>
> I'm trying to embed the python interpreter in my .NET-based program.
> The basic stuff is working fine.
> But now, I want to expose some of my program's internal data
> to the scripts.
> (ie, not just functions that live in an assembly, but access
> to my live program's state) For example, if I have a WinForms
> application, I want to be able to access a textbox's current
> text from python.
> Ideally, I should be able to do something like this from a script:
> import MyApp
> s = MyApp.GetText()
>
> Is there any way to do this in Python.NET?
> And if not, can someone provide me with some pointers on how
> to go about adding the functionality to the Python.NET code?
> (I believe we have to use issue a call to Py_InitModule or something,
> right?)
>
> Thanks,
> Haran
> _________________________________________________
> Python.NET mailing list - PythonDotNet at python.org
> http://mail.python.org/mailman/listinfo/pythondotnet
>
>
More information about the PythonDotNet
mailing list