Add open and with chapter - #60
Conversation
ee5945e to
56a6fff
Compare
e3f17bd to
cbd62ac
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cbd62ac099
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
da31ab0 to
e409357
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e4093571b0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| Programs often need data to survive after the process ends. A text file can store notes, configuration, exports, logs, or intermediate results that a later execution can read again. | ||
|
|
||
| Python's built-in `open()` function creates a **file object** connected to a file or another file-like resource. The `with` statement gives that resource a clear lifetime so it is closed even when the block exits because of an exception. |
There was a problem hiding this comment.
Limit
open() inputs to paths and descriptors
open() does not connect to an arbitrary file-like resource: it accepts a path-like value or an integer file descriptor, while passing an existing stream such as io.StringIO() raises TypeError. This wording, repeated in both translations, can therefore teach beginners that existing streams should be wrapped with open(); describe the input as a filesystem path or file descriptor instead.
AGENTS.md reference: AGENTS.md:L7-L9
Useful? React with 👍 / 👎.
Summary
open()andwith, in English, Brazilian Portuguese, and Spanishr,w,a, andx, explicit encodings, reading, writing, appending, line iteration, newline handling, and relative versus absolute pathswithto context-managed cleanup and contrast it with manualtry/finallyValidation target
mainat56a6fffadd39fddce8376347f9c82e8de49c0d58References
The chapter is grounded in the official Python 3.14 documentation for
open(), the tutorial section on reading and writing files, context-manager semantics forwith, and the built-in hierarchy for file and operating-system exceptions.