June 2017
Beginner
352 pages
8h 39m
English
Sometimes we would like to append to an existing file, and we can do that by using the mode 'a'. In with this mode, the file is opened for writing and the file pointer is moved to the end of any existing data. In this example we combine 'a' with 't' to be explicit about using text mode:
>>> h = open('wasteland.txt', mode='at', encoding='utf-8')
Although there is no writeline() method in Python, there is a writelines() method which writes an iterable series of strings to the stream. If you want line endings on your strings you must provide them yourself. This may seem odd at first, but it preserves symmetry with readlines() whilst also giving us the flexibility for using writelines() to write any iterable series of strings ...
Read now
Unlock full access