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

  • SEARCH
  • Home
  • 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 6589371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:09:56+00:00 2026-05-25T17:09:56+00:00

I have defined a class with a single function. For example: namespace my.namespace {

  • 0

I have defined a class with a single function. For example:

namespace my.namespace
{
    public class MyClass
    {
        public void some_func(string s1, string s2)
        {
            // more code here               
        }       
    }
}

I am able to load this object into an ironpython interpreter. I want to use introspection to get a list of methods that were implemented only in this class. In this example I want a list like ['some_func']. Is there a way to do it?

If I do a help(instance) on this instance I get more-or-less what I want:

class MyClass(object)
 |  MyClass()
 |  
 |  Methods defined here:
 |  
 |  __repr__(...)
 |      __repr__(self: object) -> str
 |  
 |  some_func(...)
 |      some_func(self: MyClass, s1: str, s2: str)

Of course, when I d a dir(instance) I get a lot of other functions:

>>> dir(instance)
['Equals', 'GetHashCode', 'GetType', 'MemberwiseClone', 'ReferenceEquals', 'ToString', '__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'some_func']

I want to know what instrospection method I need to use to get a list of only the functions unique to this class.

  • 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-25T17:09:57+00:00Added an answer on May 25, 2026 at 5:09 pm

    You have a number of options.

    You can (explicitly) implement the IronPython.Runtime.IPythonMembersList interface that way you can list whatever members you want to list. It’s as if you defined the __dir__ method for your class.

    public class MyClass : IronPython.Runtime.IPythonMembersList
    {
        public void some_func(string s1, string s2) { }
    
        IList<object> IronPython.Runtime.IPythonMembersList.GetMemberNames(CodeContext context)
        {
            return new[] { "some_func" };
        }
    
        IList<string> Microsoft.Scripting.Runtime.IMembersList.GetMemberNames()
        {
            return new[] { "some_func" };
        }
    }
    

    You could always define a public __dir__ method for your class as well. The return type could be anything really, but you’ll probably want to return some collection of strings.

    public class MyClass
    {
        public void some_func(string s1, string s2) { }
    
        public IEnumerable<string> __dir__()
        {
            return new[] { "some_func" };
        }
    }
    

    You always have the option to use regular .NET reflection.

    from System.Reflection import BindingFlags
    
    # you can omit the flags if you want all public .NET members
    flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly
    
    members = instance.GetType().GetMembers(flags)
    dir_members = [ mi.Name for mi in members ]
    print(dir_members)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.