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 5932429
In Process

The Archive Base Latest Questions

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

Is a way to see if a class responds to a method in Python?

  • 0

Is a way to see if a class responds to a method in Python? like in ruby:

class Fun
  def hello
    puts 'Hello'
  end
end

fun = Fun.new
puts fun.respond_to? 'hello' # true

Also is there a way to see how many arguments the method requires?

  • 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-22T14:50:00+00:00Added an answer on May 22, 2026 at 2:50 pm

    Hmmm …. I’d think that hasattr and callable would be the easiest way to accomplish the same goal:

    class Fun:
        def hello(self):
            print 'Hello'
    
    hasattr(Fun, 'hello')   # -> True
    callable(Fun.hello)     # -> True
    

    You could, of course, call callable(Fun.hello) from within an exception handling suite:

    try:
        callable(Fun.goodbye)
    except AttributeError, e:
        return False
    

    As for introspection on the number of required arguments; I think that would be of dubious value to the language (even if it existed in Python) because that would tell you nothing about the required semantics. Given both the ease with which one can define optional/defaulted arguments and variable argument functions and methods in Python it seems that knowing the “required” number of arguments for a function would be of very little value (from a programmatic/introspective perspective).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

what do you see as best way of presenting class names in LaTeX documents
Is there a way to see what's been saved to NSUserDefaults directly? I'd like
Is there any way to see what a control will look like in the
I have another class that creates the connection (see refined class half way down
Given that this is the correct way to see if 'this' has class 'selected':
It's hard to get a word for this. Sometimes I see a class like
Is it completely against the Java way to create struct like objects? class SomeData1
class Api::StoresController < ApplicationController respond_to :json def index @stores = Store.all(:include => :products) respond_with
The way I see it, (correct me if I'm wrong) a class is cached,
Is there any way to see an overview of what kind of queries are

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.