Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Juan-Carlos-Cruz/robotaxi-zoox/llms.txt

Use this file to discover all available pages before exploring further.

leer_mapa reads a space-separated integer text file and returns a list-of-lists matrix ready to pass to Grid. It is the standard entry point for loading any of the project’s map files and handles all I/O concerns — path resolution, encoding, empty-line skipping, and error reporting — so calling code never has to open files directly. When no path is given, leer_mapa defaults to mapas/test/Prueba1.txt relative to the project root.
from mundo import leer_mapa

Function signature

leer_mapa(ruta=None)

Reads the file at ruta, parses every non-empty line as a row of whitespace-separated integers, and returns the resulting matrix. All errors are caught internally and reported to stdout; the function never raises.
ruta
str | Path | None
default:"None"
Path to the .txt map file to load. Accepts a plain string, a pathlib.Path object, or None. When None, the function resolves the default map path automatically — see Behavior details below.
result
list[list[int]] | None
A 2D list of integers where each inner list corresponds to one row of the map. Returns None if the file is not found, contains no parseable rows, or any other error occurs during reading.

Behavior details

Default path resolution. When ruta is None, the function calls the private helper _ruta_mapa_predeterminada(), which constructs an absolute path by resolving the project root (RUTA_PROYECTO) at import time and appending mapas/test/Prueba1.txt. This means the default path is always correct regardless of the working directory from which the script is run. Empty-line handling. Each line is stripped of leading and trailing whitespace before processing. Lines that are empty after stripping are silently skipped, so map files may contain blank separator lines without causing errors. Integer conversion. Each non-empty line is split on whitespace and every token is converted with int(). The cell-type integers correspond directly to the constants on Grid (05). Error handling. Two error conditions are caught:
  • FileNotFoundError — prints Error: No se encontró el archivo <path> to stdout and returns None.
  • Any other exception during parsing — prints Error al leer archivo: <error> to stdout and returns None.
The function does not raise in either case. Empty file guard. If the file exists but contains no parseable rows (all lines are blank), the function returns None rather than an empty list.
Always check the return value for None before passing the matrix to Grid. Passing None to Grid(matriz) will raise a TypeError because len(None) is not defined. leer_mapa returns None silently on all error paths.

Examples

from mundo import leer_mapa, Grid

# Load the default map (mapas/test/Prueba1.txt)
matriz = leer_mapa()
print(type(matriz))   # <class 'list'>
print(len(matriz))    # number of rows in the default map
# Load a specific map and construct a Grid from it
matriz = leer_mapa('mapas/test/Prueba3.txt')
if matriz is not None:
    grid = Grid(matriz)
    print(grid.inicio, grid.destino)
else:
    print("Map file could not be loaded.")
# Using a pathlib.Path object
from pathlib import Path
from mundo import leer_mapa

ruta = Path('mapas') / 'test' / 'Prueba2.txt'
matriz = leer_mapa(ruta)

if matriz is not None:
    print(f"Loaded {len(matriz)} rows × {len(matriz[0])} columns")

Private helper

_ruta_mapa_predeterminada()

Builds the absolute Path object for the default map file. It is called automatically by leer_mapa when ruta=None and is not part of the public API — do not call it directly from application code.
result
Path
Absolute path to <project_root>/mapas/test/Prueba1.txt, where project_root is resolved relative to the map_loader.py source file at import time using Path(__file__).resolve().parents[2].
RUTA_PROYECTO (the project root constant used by _ruta_mapa_predeterminada) is resolved once when the mundo.io module is first imported. If you move the source tree after import, the cached path will not update. In tests or scripts that manipulate the file system, always pass an explicit ruta argument to leer_mapa rather than relying on the default.

Build docs developers (and LLMs) love