Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Open Source > Python
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 19th, 2013, 05:42 AM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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";
        }
    }
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 03: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



All times are GMT -4. The time now is 05:15 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.