โ† All Python Flashcard Decks

Modules and Packages Flashcards

7 cards from real Python practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 7 Modules and Packages flashcards as text
  1. What does a relative import like `from . import utils` do?

    Answer: Imports `utils` from the same package as the current module

    A single leading dot (`.`) means the import is relative to the current package, so `from . import utils` loads a sibling module.

  2. Where does `pip install` place packages by default?

    Answer: In the `site-packages` directory of the active Python environment

    `pip install` places packages in the `site-packages` directory of the currently active Python interpreter or virtual environment.

  3. What is the role of `setup.py` in a Python package?

    Answer: It defines package metadata and build instructions for distribution

    `setup.py` uses `setuptools.setup()` to declare package metadata, dependencies, and entry points for building and distributing a package.

  4. Which module provides the `find_spec()` function for inspecting how a module would be imported?

    Answer: importlib.util

    `importlib.util.find_spec('module_name')` returns a `ModuleSpec` describing how the module would be located and loaded.

  5. What does `from ..sibling import helper` mean in a package?

    Answer: Import `helper` from a module in the parent package's `sibling` subpackage

    Two dots (`..`) navigate to the parent package, so `from ..sibling import helper` imports from a subpackage that is a sibling of the current package.

  6. Which tool is the modern standard for declaring package dependencies and metadata, replacing `setup.py`?

    Answer: pyproject.toml

    PEP 517/518 standardized `pyproject.toml` as the build-system configuration file, and tools like `setuptools`, `flit`, and `poetry` use it instead of `setup.py`.

  7. What happens when you run `python -m mypackage`?

    Answer: Python executes `mypackage/__main__.py` if it exists

    The `-m` flag runs a module or package as a script; for a package it looks for and executes `__main__.py`.