About 634,000 results
Open links in new tab
  1. python - How to get a function name as a string? - Stack Overflow

    Apr 17, 2022 · To get the current function's or method's name from inside it, consider: sys._getframe also works instead of inspect.currentframe although the latter avoids accessing a private function. To get the calling function's name instead, consider f_back as in inspect.currentframe().f_back.f_code.co_name. If also using mypy, it can complain that:

  2. Python | How to get function name - GeeksforGeeks

    Apr 6, 2023 · The task of getting a list of parameter names from a function in Python involves extracting the function's arguments using different techniques. These methods allow retrieving parameter names efficiently, whether from bytecode, introspection or source code analysis.

  3. What is the naming convention in Python for variables and functions

    Function names should be lowercase, with words separated by underscores as necessary to improve readability. Variable names follow the same convention as function names. mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility. PEP = Python Enhancement Proposal.

  4. python - Determine function name from within that function - Stack Overflow

    Aug 27, 2016 · Is there a way to determine a function's name from within the function? def foo(): print("my name is", __myname__) # <== how do I calculate this at runtime? In the example above, the body of foo will somehow access the function name "foo" without hard-coding it. The output would be: >>> foo() my name is foo

  5. How to Get the Name of a Function in Python? - Python Guides

    Feb 10, 2025 · In this tutorial, I explained how to get the name of a function in Python. I discussed three methods to accomplish tasks such as using the _name_attribute , using the inspect module , and using decorators to log function names .

  6. 5 Best Ways to Retrieve a Function Name in Python

    Mar 11, 2024 · To get the function name, you can use inspect.getframeinfo() or inspect.currentframe() combined with function.__code__. Here’s an example: print("Hello World!") Output: <module> This snippet retrieves the frame information for the current execution frame and gets the name of the function from it.

  7. How Do You Choose Python Function Names? – Real Python

    Jul 10, 2024 · In this tutorial, you learned how to choose Python function names that follow the core naming rules and the conventions defined by Python’s style guide. Function names contain all lowercase letters.

  8. How to Get Function Name in Python - Delft Stack

    Feb 2, 2024 · This comprehensive article delves into various methods for retrieving a function’s name in Python, providing in-depth explanations and examples. Method 1: Use the __name__ Property to Get the Function Name in Python

  9. Python Functions - Python Guides

    What are Functions in Python? A function is a block of organized, reusable code that performs a specific task. Functions help break our program into smaller and modular chunks, making it more organized and manageable. Defining a Function. In Python, you define a function using the def keyword, followed by the function name and parameters in ...

  10. Unveiling Function Names in Python: A Comprehensive Guide

    Mar 20, 2025 · Knowing how to obtain the name of a function can be incredibly useful in various scenarios, such as debugging, logging, and metaprogramming. This blog post will delve deep into the concept of getting function names in Python, exploring different methods, common use cases, and best practices. 2. Table of Contents. 3.

  11. Some results have been removed
Refresh