June 2017
Beginner
352 pages
8h 39m
English
Let's start working with files by opening a file in write mode. We'll be explicit about using the UTF-8 encoding, because we have no way of knowing what your default encoding is. We'll also use keyword arguments to make things clearer still:
>>> f = open('wasteland.txt', mode='wt', encoding='utf-8')
The first argument is the filename. The mode argument is a string containing letters with different meanings. In this case w means write and t means text.
All mode strings should consist of one of read, write or append mode. This table lists the mode codes along with their meanings in the following format Code: Meaning :
Read now
Unlock full access