Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4611056
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:12:59+00:00 2026-05-22T01:12:59+00:00

First of all I am new to python and a bit rusty on .NET

  • 0

First of all I am new to python and a bit rusty on .NET so bear with me if this sounds
too obvious.
Assuming the following python classes;

class foo1(object):
      def bar1(self):
         print "bar1 called."
      def bar2(self):
         print "bar2 called."
class foo2 ..... same as above

I want to store the class methods somewhere and want to invoke them on an object of my own choosing.This is what I came up with.

ObjectOperations ops = engine.Operations;
IList<string> members = ops.GetMemberNames(scope);
foreach(string member in members)
{
   if(member.StartsWith("foo"))
      {
         dynamic klass= scope.GetVariable(member);
         dynamic instance= klass();
         //for brevity I am skipping the enumeration of
         //function names here.
         dynamic func = ops.GetMember(instance, "bar1");//and store it somewhere
         Action act = ops.ConvertTo<Action>(func); //This part is not really necessary

       }
}

What I want to do is invoking the func(of type IronPython.Runtime.Method) on a instance I create sometime later. From what I glean from IronPython source that the instance is set in stone when it’s created and I cannot change it.Is there a way accomplish this? I am also not sure in what context(scope??) to run the function or I shouldn’t worry about it all.

ObjectOperations do have a method called MemberInvoke that takes a object and member name but I’d rather prefer MethodInfo.Invoke type of invocation both for style and performance considerations.

Any pointers would be greatly appreciated.

P.S. I am using IronPython 2.7 and .Net4.0 by the way..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:13:00+00:00Added an answer on May 22, 2026 at 1:13 am

    Yes, this is actually very easy. In Python methods can either be invoked as bound methods such as:

    x = C().f  # produces a bound method
    x() # invokes the bound method
    

    Which is the same as:

    C().f()
    

    Or they can be invoked with an explicit self parameter:

    C.f(C())
    

    This works the same way from the hosting APIs, so all you need to do is something like:

    dynamic klass = scope.GetVariable(member);
    dynamic func = ops.GetMember(klass, "bar1");
    
    // and then later:
    func(inst);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, I'm really new to the MVC Asp.Net ideology. I would like
First of all, I'm fairly new to Java, so sorry if this question is
I am new to Python and this is my first time asking a stackOverflow
I'm new to python and have been trying to figure this out all day.
Hi there First of all just let me say that I'm new in Python
first of all I'm new to python and programming but you guys already helped
first of all I'm totally new to FAST but I already have a couple
First of all, I'm kinda new to the barcode formats and what I do
I am new here so first of all my greetings to you I am
First of all, let me say I am very new to rails, have been

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.