Sibling imports
The module you documented in the last exercise, impyrial
, is growing and you have separated the private functions (the ones you don't really want your users to use) from your public functions. The private functions are in the core.py
module and the public ones are in the api.py
module.
However, you need to use the private functions to make the public functions work. In this exercise, you will import them into the api.py
module to get your package modules working together.
Note: Please make sure that you run the example_script.py
. If you run the api.py
file, you get an
ModuleNotFoundError: No module named 'impyrial'
as is expected.
Remember that you can open/close the folder and files overview by clicking on the icon on the left side of the editor highlighted in red.
This exercise is part of the course
Developing Python Packages
Exercise instructions
- Import the functions
inches_to_feet()
andinches_to_yards()
, and the variableUNITS
from theimpyrial/length/core.py
module intoimpyrial/length/api.py
. Use an absolute import. - Import the function
convert_unit()
function inimpyrial/length/api.py
into theexample_script.py
script. You'll need to import this using the full filepath to theapi
module. - Run the
example_script.py
to check that your imports work.
Hands-on interactive exercise
Turn theory into action with one of our interactive exercises
