Loading topic
str and bytes, and how try/except works. You do not need any prior experience with files.3 min readstr and bytes, and how try/except works. The with statement is covered in the next chapter, so the examples here use it without explaining it.2 min readstr and bytes, and how try/except works. You have seen that open() returns a file object. Here you will learn why that object must be closed and how the with statement does it for you.3 min readopen() returns a file object, how the "r" mode works, and how a with block closes the file. You should also be comfortable with try/except and with the difference between str and bytes. This chapter covers the ways to get text out of a file once it is open.3 min readwrite() and writelines(), and choosing between overwriting and appending. It assumes you know basic Python syntax, the difference between str and bytes, and try/except. It also assumes you have seen file modes and the with statement.3 min readopen() with the with statement, read and write text files, and tell str from bytes. It covers two settings that decide what ends up on disk: the encoding and the newline handling.3 min readopen() and use the with statement, and that you know basic string methods. It covers the pathlib module, which represents file paths as objects instead of strings.3 min readPath object, know what open() returns, and understand the with statement and text encodings from earlier chapters. It covers the four Path methods that read or write a whole file in one call, and when to use them instead of open().2 min readopen() and the with statement, and that you know basic try/except. It shows how to handle the failures that file operations raise most often.2 min readopen(), use the with statement, and tell str from bytes. Text mode decodes bytes into strings for you. Binary mode skips that step and gives you the raw bytes.3 min readwith open(...), set an explicit encoding, and handle basic exceptions. CSV and JSON are the two text formats you will meet most often. Python's standard library reads and writes both, so you need no extra packages.2 min readwith open(...), know the difference between str and bytes, and have used the modes r, w, a and b. Here you will learn how to read the current position in a file and jump to another one.2 min readwith, write text with an explicit encoding, build paths with pathlib, and catch exceptions with try/except. It covers one problem: a program that crashes while writing can leave a file half-written.3 min read