Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] Problem with calling the Python function in C# Application

Started by narasimhakumar_k Oct 13, 2005 at 10:16 AM 0 replies 400+ views
Original Post
narasimhakumar_k
narasimhakumar_k
I have problem with calling a python function(in .py file) using C# I used

PyPortalFun.py
def fun():
    print "hai"
I included the Python.Runtime dll I have written C# code as

using System;
using Python.Runtime;
namespace MainProgram
{
	
	class PyTestClass
	{
		
		public PyTestClass()
		{
			PythonEngine.Initialize();
		} 
		[STAThread]
		static void Main(string[] args)
		{
			PyTestClass pyTest = new PyTestClass();
			try
			{
				if(!PythonEngine.IsInitialized)
					throw new  Exception("PythonEngine not initialized.");			  
			
				PyObject module= PythonEngine.ImportModule("PyPortalFun");	
				
			}
	
			catch(Exception e)
			{
				Console.WriteLine(e.Message);
				Console.Write(e.StackTrace);
			}
		}
	}
}

[Added the [source] tag to preserve formatting and add syntax highlighting - Oluseyi] In the Above program i am loading only the module name as pyPortalFun But i have a problem with calling fun() function in PyPortalFun.py from C# Thanks.. K.V.N.Kumar Apollo Health Street Limited narasimhakumar_k@apollolife.com Hyderabad [Edited by - Oluseyi on October 13, 2005 12:40:53 PM]
Oluseyi
Oluseyi
Could you give us more information, such as any error messages you receive? Does your project include a reference to the Python runtime assembly? Have you considered simply using IronPython instead?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.