Discussion:
[Python.NET] How to manipulate python module property from C#?
Charles Chiu
2008-02-08 15:16:44 UTC
Permalink
Hi Everyone,
I just found out python for .net yesterday and
would be interested in knowing about this. I have
tried to test it myself however, i couldn't figure out
what is wrong with the code i wrote. I am trying to
invoke a simple method hello() from Hello.py
here is the code i wrote:

namespace PyWrapper
{
class Program
{
static void Main(string[] args)
{
PythonEngine.Initialize();
PyObject sys =
PythonEngine.ImportModule("sys");
string actual_path =
sys.GetAttr("path").ToString();
Console.WriteLine(actual_path);
string path = "my path to the py file";

PyObject hello =
PythonEngine.ImportModule("hello");
// PyObject hello remins null after the
line above which i suspect that is the reason the next
line crashes.
string fromPython =
hello.InvokeMethod("hello", new PyTuple()).ToString();
PythonEngine.Shutdown();
}
}
}

Can someone give me some suggestion on what kind of
problem this could be? thanks


____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping
_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet
Brian Lloyd
2008-02-08 20:22:16 UTC
Permalink
imports are case-sensitive, so you probably have to do
ImportModule("Hello").

-Brian
Post by Charles Chiu
Hi Everyone,
I just found out python for .net yesterday and
would be interested in knowing about this. I have
tried to test it myself however, i couldn't figure out
what is wrong with the code i wrote. I am trying to
invoke a simple method hello() from Hello.py
namespace PyWrapper
{
class Program
{
static void Main(string[] args)
{
PythonEngine.Initialize();
PyObject sys =
PythonEngine.ImportModule("sys");
string actual_path =
sys.GetAttr("path").ToString();
Console.WriteLine(actual_path);
string path = "my path to the py file";
PyObject hello =
PythonEngine.ImportModule("hello");
// PyObject hello remins null after the
line above which i suspect that is the reason the next
line crashes.
string fromPython =
hello.InvokeMethod("hello", new PyTuple()).ToString();
PythonEngine.Shutdown();
}
}
}
Can someone give me some suggestion on what kind of
problem this could be? thanks
______________________________________________________________________________
______
Looking for last minute shopping deals?
Find them fast with Yahoo! Search.
http://tools.search.yahoo.com/newsearch/category.php?category=shopping
_________________________________________________
http://mail.python.org/mailman/listinfo/pythondotnet
--------------------------
Brian Lloyd

brian.lloyd-IsS0qfAs25g7rjH4CWuWblaTQe2KTcn/@public.gmane.org

_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet

Loading...