June 2025
Beginner to intermediate
473 pages
13h 30m
English
Before you can read or write a text file, you must open the file via open. Then, you can pass the filename in the first parameter and the access mode in the second. With the additional letter b, you can also process binary files, but we won’t cover this topic here.
|
Mode |
Meaning |
|---|---|
|
'r' |
Read file (applies by default) |
|
'w' |
Write file (existing files will be overwritten!) |
|
'a' |
Write to the end of an existing file (append) |
|
'r+' |
Read and write file |
Table 5.9 Access Modes of the Open Method
open returns a file object, which can then be processed with various methods. close() terminates access to the file and releases it again for other programs. In short scripts, you can do without
Read now
Unlock full access