How to manipulate python module property from C#?
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
imports are case-sensitive, so you probably have to do ImportModule("Hello"). -Brian On 2/8/08 10:16 AM, "Charles Chiu" <charles5557@yahoo.com> wrote:
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@python.org http://mail.python.org/mailman/listinfo/pythondotnet
-------------------------- Brian Lloyd brian.lloyd@revolutionhealth.com
participants (2)
-
Brian Lloyd
-
Charles Chiu