Relative Imports (Inside the Package) Dry Run in PYTHON

Relative Imports (Inside the Package) is an interactive PYTHON dry run visualizer from the Packages programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.

This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.

Relative Imports (Inside the Package) Program Code

# File 1: mygame/utils.py
def calculate_health(name):
    return 100 + len(name)

# File 2: mygame/characters/hero.py
class Warrior:
    def __init__(self, name):
        self.name = name
    
    def get_health(self):
        # Two dots move from characters to the parent mygame package
        from ..utils import calculate_health
        return calculate_health(self.name)

# File 3: mygame/characters/__init__.py
from .hero import Warrior

# File 4: main.py
from mygame.characters import Warrior

player = Warrior("Aragon")
print("Player health:", player.get_health())

View the complete Packages programs page.

Program Console Relative Imports (Inside the Package) Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.