Skip to content

Latest commit

Β 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

README.md

βš—οΈ Python Module 06 β€” The Codex: Import Mysteries

This project is part of the 42 School Common Core and focuses on
advanced Python code organization through the import system.

Building on previous modules, this project introduces the concept of
modular architecture and package design, using a themed
alchemy laboratory system.

The goal of this module is to understand and apply:

  • Python packages and __init__.py
  • module organization and exposure control
  • different import styles (import, from ... import, aliases)
  • absolute vs relative imports
  • circular dependency problems and solutions
  • clean project structure and scalability
  • error handling through controlled returns

Each part explores a core concept of Python imports, resulting in a
fully structured and reusable Alchemy package system.


πŸ“ Project Structure

All files are organized at the root of the repository, with a main package:

alchemy/
β”œβ”€β”€ init.py
β”œβ”€β”€ elements.py
β”œβ”€β”€ potions.py
β”œβ”€β”€ transmutation/
β”‚ β”œβ”€β”€ init.py
β”‚ β”œβ”€β”€ basic.py
β”‚ └── advanced.py
└── grimoire/
β”‚ β”œβ”€β”€ init.py
β”‚ β”œβ”€β”€ spellbook.py
β”” β”œβ”€β”€ validator.py

Demonstration scripts (mains):

- `ft_sacred_scroll.py`
- `ft_import_transmutation.py`
- `ft_pathway_debate.py`
- `ft_circular_curse.py`

πŸ“Œ Exercises Overview

Part I β€” The Sacred Scroll

Introduces Python packages and __init__.py.

  • Creates the alchemy package
  • Controls what functions are exposed
  • Demonstrates package vs module access

Concepts: package initialization, interface control, encapsulation


Part II β€” Import Transmutation

Focuses on different import styles.

  • Uses import, from ... import, aliases
  • Builds potion functions using elements
  • Demonstrates how imports affect readability and usage

Concepts: import styles, code reuse, modular calls


Part III β€” The Great Pathway Debate

Explores absolute vs relative imports.

  • Implements nested package (transmutation)
  • Uses both import styles
  • Shows how both reach the same functionality

Concepts: absolute imports, relative imports, package navigation


Part IV β€” Breaking the Circular Curse

Introduces circular dependencies and solutions.

  • Simulates dependency conflicts between modules
  • Implements validation system
  • Uses techniques to avoid circular imports

Concepts: circular dependencies, late imports, dependency design


βš™οΈ Key Learning Points

  • __init__.py defines what a package exposes
  • Imports are not just syntax β€” they define architecture
  • Relative imports improve maintainability inside packages
  • Absolute imports improve clarity and readability
  • Circular dependencies are a design problem, not just a bug
  • Clean structure > complex logic

βœ… Notes

  • Written for Python 3.10+
  • Fully compliant with flake8
  • Follows 42 naming conventions
  • All functions return strings (as required)
  • Focus is on import behavior, not algorithm complexity
  • Outputs match the subject examples exactly