Closed AlanLivingston closed 2 years ago
example
is not imported by __init__.py
. So import example_package
only imports example_package/__init__.py
, and not example_package/example.py
. So it's not available. You can do:
import example_package.example
example_package.example.add_one(2)
If you want. You can also import example_package.example
inside example_package/__init__.py
, but be warned that means anyone using the package will always import example.py
(if it's optional and there are any expensive setup code, special imports, etc. you might not always want that).
Ok, thanks! That was a concept I was missing.
OS version
Windows 10
Python version
Python 3.10.2
Pip version
pip 22.1.2
Guide link
https://packaging.python.org/en/latest/tutorials/packaging-projects/
Problem description
At the end of the tutorial, it imports the package, and runs the exported function:
But if I just enter:
What I expected was to do _import example_package_, and then invoke addone with example_package.example.add_one(2)_
Why doesn't this work?
Error message
No response