[Python.NET] How to manipulate python module property from C#?

Charles Chiu charles5557 at yahoo.com
Fri Feb 8 16:16:44 CET 2008


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


More information about the PythonDotNet mailing list