Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Open Source > Python
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Python section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 19th, 2013, 05:42 AM
Registered User
 
Join Date: Jul 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to call .net method in python ?

Hi,

I have created a c# program, which will call python method and passing .net dynamic object to that python method and I don't know why it is not calling instance member (NOTE: when i override a ToString() method it is calling the corresponding class here Demo class ToString() method)

Kindly help me please.....

My pythonscripts.py has method

def CallInstance(obj):
print obj.objectType

def CallMethod(obj):
print obj.objectType.Test()

My .net code is here

Code:
    class SampleScriptLanguage
    {
        ScriptRuntime _scriptRuntime = Python.CreateRuntime();
        ScriptEngine _scriptEngine;
        ScriptSource _scriptSource;
        ScriptScope _scriptScope;
        string scriptToUse;

        public SampleScriptLanguage()
        {
            _scriptEngine = _scriptRuntime.GetEngine("Python");
            dynamic _scriptScope = _scriptRuntime.UseFile("PythonScripts.py");
            dynamic expandObject1 = new ExpandoObject();
            expandObject1.objectType = new Demo();
            _scriptScope.CallInstance(expandObject1); // This is working
            _scriptScope.CallMethod(expandObject1); // This is not working
        }
    }

 class Demo
    {
        public string ID
        {
            get
            {
                return this.Test();
            }
        }

        public string Test()
        {
            return "Test Method";
        }

        public override string ToString()
        {
            return "To string method";
        }
    }





Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling a function on every method call Takashi321 General .NET 1 September 21st, 2007 09:33 AM
how to call a method from childMDI1 into childMDI2 raj_k C# 0 June 26th, 2005 04:54 PM
How to call a C# method from VB.Net? aliarifpk General .NET 1 February 26th, 2004 04:11 AM
How to call method written in VB.NET from C# proje salmaan Crystal Reports 0 September 12th, 2003 03:32 PM
How to call method written in VB.NET from C# proje salmaan BOOK: Professional C#, 2nd and 3rd Editions 0 September 12th, 2003 03:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.