By the end of this lab, you will be able to:
- Create a multi-level package structure using directories and
__init__.pyfiles - Understand the difference between modules (
.pyfiles) and regular packages (directories with__init__.py) - Use relative imports to share code between modules in the same package
- Control namespace visibility using
__init__.pyfiles - Import modules and attributes using various import syntaxes
- Understand how Python's import system affects attribute access
- Follow these setup instructions, then return here to get started
- Navigate to the new
animal-classificationdirectory in your terminal - You'll build your entire package structure from scratch in this directory
In this lab, you'll create a package structure that models the biological classification of vertebrate animals. You'll organize animals into a hierarchy that mirrors taxonomic relationships, and learn how Python's import system allows you to access attributes and modules at different levels of the hierarchy.
You'll create a package hierarchy that mirrors the biological classification of vertebrates, which are animals with backbones. The structure, as shown in the following diagram, organizes vertebrates by their characteristics (warm-blooded vs. cold-blooded) and then by their specific classification (fish, mammals, birds, etc.).
Your Goal: Design and implement a package structure where:
- Each level of classification is represented by a package (directory with
__init__.py) - Individual animals are modules (
.pyfiles) - Shared characteristics for each classification are stored in a way that all animals in that group can access them
- You can import animals and their attributes at different levels of the hierarchy
You'll also create a main.py file at the root of your workspace to test your package structure.
If you're ready, go to the first part of the lab using the navigation below!
