About 2,530,000 results
Open links in new tab
  1. python - How do I call a function from another .py file? - Stack Overflow

    You can call the function from a different directory as well, in case you cannot or do not want to have the function in the same directory you are working. You can do this in two ways (perhaps there are more alternatives, but these are the ones that have worked for me).

  2. python - Calling a function of a module by using its name (a …

    Jun 4, 2022 · How do I call a function, using a string with the function's name? For example: import foo func_name = "bar" call(foo, func_name) # calls foo.bar()

  3. python - How to get a reference to a module inside the module

    Jan 9, 2019 · You can get the name of the current module using __name__. The module reference can be found in the sys.modules dictionary. See the Python documentation

  4. Python – Call function from another file - GeeksforGeeks

    Aug 21, 2024 · Given a Python file, we need to call a function in it defined in any other Python file. Example: Suppose there is a file test.py which contains the definition of the function displayText(). #test.py> def displayText(): print( “Geeks 4 Geeks!”)

  5. How to Import Local Modules with Python - GeeksforGeeks

    Jun 28, 2024 · In this article, we will understand how to import local modules with Python. Python Modules: Think of them as individual Python files (e.g., mymodule.py) containing code to reuse. Python Packages: These are directories (with an __init__.py file) that group related modules together, creating a hierarchical structure.

  6. Python Modules - W3Schools

    Note: When using a function from a module, use the syntax: module_name.function_name. Variables in Module The module can contain functions, as already described, but also variables of all types (arrays, dictionaries, objects etc):

  7. Here is how to call a function of a module by using its name in Python

    To call a function of a module by using its name in Python, you can use the getattr function. Alternatively, you can also use the globals() function to retrieve the function from the global namespace.

  8. Obtaining a Reference to a Module within Itself in Python 3

    Obtaining a reference to a module within itself in Python 3 is essential in certain scenarios where a module needs to access its own attributes or invoke its own functions. By utilizing the __name__ attribute, the sys module, or the inspect module, developers can easily achieve this self-reference.

  9. Python 3: Import Another Python File as a Module

    Mar 25, 2021 · In Python, a module is a single unit of Python code that can be imported (loaded and used) by other Python code. A module can contain definitions (like functions and constants), as well as statements that initialize those definitions. Once the module code is written, it can be reused by any script that imports the module. A common way to create ...

  10. Python Tutorial: How to Reference Modules in Python?

    Oct 21, 2024 · One of its powerful features is the ability to use modules, which are files containing Python code that can define functions, classes, and variables. This tutorial will guide you through the process of referencing modules in Python, providing you with the knowledge to effectively utilize them in your projects.

  11. Some results have been removed
Refresh