Calling a function defined in __init__.py
📁 function, Advanced Python Topics, example, AI, project
When initializing a package in Python 2.7, I need to define functions that should be common to all modules of this package. I defined them in __init__.py. How do I call it from inside the package? From outside it works like this:
import package.modulepackage.foo() # callInside the package (for example in module module), foo is not defined, dir(__package__) also does not show this function.
Project structure:
package\\ # package __init__.py # function here module.py # I need to call the function here To be brief, NO.
In more detail, look at the discussion here. There are also solution options such as using optional or keyword arguments.
Log in to leave an answer
Blogs
Java vs Python: What to Choose for Backend in 2024?
Kotlin for Machine Learning: Opportunities and Limitations in Practice
Swift vs Python for Backend: What to Choose for a Beginner in 2025
Jetpack Compose Column: Why Centering Doesn't Work and How to Fix It