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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:37:07+00:00 2026-05-22T23:37:07+00:00

Possible Duplicate: How do I get the name of a function or method from

  • 0

Possible Duplicate:
How do I get the name of a function or method from within a Python function or method?

The below code function return it’s name.
It works but I still have to specify the ‘test.’ in front of of the __name__.
Is there any general way to refer the __name__ ?

def test():
   print test.__name__
  • 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-22T23:37:08+00:00Added an answer on May 22, 2026 at 11:37 pm

    There is no way to access the function name in a python function without using a backtrace.

    In [1]: import inspect
    
    In [2]: def test():
       ...:     print inspect.stack()[0][3]
       ...:
    
    In [3]: test()
    test
    

    So, what you want to use is inspect.stack()[0][3] or, if you want to move it into a separate function, inspect.stack()[1][3]

    (from How do I get the name of a function or method from within a Python function or method?)

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

Sidebar

Related Questions

Possible Duplicate: How do I get the name of a function or method from
Possible Duplicate: How to get the function name as string in Python? I know
Possible Duplicate: Return value from thread I want to get the free memory of
Possible Duplicate: How can I get the name of function inside a JavaScript function?
Possible Duplicate: Why do multiple-inherited functions with same name but different signatures not get
Possible Duplicate: Reflection in C#: How do I get the calling method name and
Possible Duplicate: iOS: How to get a proper Month name from a number? How
Possible Duplicate: jQuery: get the file name selected from <input type=file /> I have
Possible Duplicate: Calling a Function From a String With the Function's Name in Ruby
Possible Duplicate: Returning multiple values from a C++ function /************************************************/ /* Name: premserv */

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.