Language Reference
Context managers
Use readable with statements for safe resource management.
Context basics
- Use
withfor resources. - Bind names with
as. - Keep cleanup automatic.
With statements
Open files or resources and let Python handle cleanup automatically.
context.pln
with open("data.json", "r") as file do data = json.load(file)
Multi-line context blocks
Use indentation when the context block needs multiple steps.
context_block.pln
with open("report.txt", "w") as handle do
handle.write("Summary")
handle.write("\nDone")
Context tips
- Always use
withfor file access. - Keep context blocks small and focused.
- Combine with error handling for safe IO.