9.3 Text-File Processing

In this section, we’ll write a simple text file that might be used by an accounts-receivable system to track the money owed by a company’s clients. We’ll then read that text file to confirm that it contains the data. For each client, we’ll store the client’s account number, last name and account balance owed to the company. Together, these data fields represent a client record. Python imposes no structure on a file, so notions such as records do not exist natively in Python. Programmers must structure files to meet their applications’ requirements. We’ll create and maintain this file in order by account number. In this sense, the account number may be thought of as a record key. For this chapter, we assume that you launch ...

Get Intro to Python for Computer Science and Data Science: Learning to Program with AI, Big Data and The Cloud now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.