Notes to File Away

In this chapter, you learned the following:

  • When files are opened and read, their contents are commonly stored in lists of strings.

  • Data stored in files is usually formatted in one of a small number of ways, from one value per line to multiline records with explicit end-of-record markers. Each format can be processed in a stereotypical way.

  • Data processing programs should be broken into input, processing, and output stages so that each can be reused independently.

  • Files can be read (content retrieved), written to (content replaced), and added to (new content appended). When a file is opened in writing mode and it doesn’t exist, a new file is created.

  • Data files come in many different formats, so custom code is often required, but we can reuse as much as possible by writing helper functions.

  • To make the functions usable by different types of readers, the reader (for a file or web page) is opened outside the function, passed as an argument to the function, and then closed outside the function.

  • typing.TextIO is used in type annotations to indicate an open file.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.146.35.72