On this page
Spell ids and lookup๏
๐ก Intermediate ยท Lesson 13
bind() answers with the spell's id string - keep it, and the book will hand the living Spell record back on request.
Before you run๏
Use the Intermediate guide for prerequisite concepts. Run from a checkout with Melder installed and Python 3.14 free-threading selected. The collection download includes the level's local helper modules.
Run the saved script๏
python UX_and_AIX_experiences/02_intermediate/13_spell_ids_and_lookup.py
py -3.14t UX_and_AIX_experiences/02_intermediate/13_spell_ids_and_lookup.py
Public surface๏
bind() -> str, md.Spellbook.find_spell_by_id, md.Spell
Code๏
1"""
2TIER: intermediate (13)
3GOAL: bind() answers with the spell's id string - keep it, and the book
4 will hand the living Spell record back on request.
5SURFACE EXERCISED: bind() -> str, md.Spellbook.find_spell_by_id, md.Spell
6"""
7import melder as md
8
9
10class Catalogued:
11 pass
12
13
14def main() -> None:
15 book = md.Spellbook()
16 spell_id = book.bind(spell=Catalogued, existence="unique")
17 assert isinstance(spell_id, str) and spell_id
18 print("bind returned id:", spell_id[:12], "...")
19
20 record = book.find_spell_by_id(spell_id)
21 assert record is not None and isinstance(record, md.Spell)
22 print("book answered with a living record:", type(record).__name__)
23 missing = book.find_spell_by_id("no-such-spell")
24 print("unknown id answers honestly:", missing)
25
26
27if __name__ == "__main__":
28 main()
Check the outcome๏
The script contains its own assertions or demonstrated refusal paths. Run it to evaluate those checks against your installed version. The code above is taken directly from the saved file; no run output is invented here.