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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:16:32+00:00 2026-06-04T07:16:32+00:00

I am having problems passing a method in a function. I have already looked

  • 0

I am having problems passing a method in a function. I have already looked at this previous post.

How do I pass a method as a parameter in Python

Here is a simple example of what I tried.

def passMethod(obj, method):
    return obj.method()

passMethod('Hi', lower)

In the end I will use this to help write a function dealing with GIS (Geographic Information Systems) data. The data is like an array. I want to add a new column NAME1 to the array. The array then has a method to call the column array.NAME1.

Regards,
Alex

  • 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-06-04T07:16:33+00:00Added an answer on June 4, 2026 at 7:16 am

    When you give the name lower, that means to look up the name lower in the global namespace. It isn’t there, because you’re looking for the lower method of strings (the str class). That is spelled str.lower.

    Then, in your function, obj.method means to look up the method attribute of the obj. It has nothing to do with the parameter named method, and cannot work that way. Instead, since you have an unbound method, pass the object as the self parameter explicitly: thus, method(obj). That gives us:

    def passMethod(obj, method):
        return method(obj)
    
    passMethod('Hi', str.lower)
    

    Alternately, we could use a string as the name of the method to look up on the passed-in object. That looks like:

    def passMethod(obj, method):
        return getattr(obj, method)()
    
    passMethod('Hi', 'lower')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having problems with passing arguments to new threads, I have the following
I'm having problems passing an array parameter to my .ashx handler. Querystring parameters work
I've been having problems passing parameters from one .jsp to another. I have two
I'm having some problems with Jquery UI Dialog and TinyMCE. Passing data to a
I am having some problems parsing this piece of XML using SimpleXML. There is
I'm having problems with parsing a decimal string to a byte. This is the
I am having a problem with views. I have a view and am passing
I'm having problems passing information, updating progress and indicating done with a SwingWorker class
Im having problems passing PHP Strings to Javascript functions, I'v read a number of
I'm having a problem understanding what I'm doing wrong here. I have the code

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.