Python is a general-purpose interpreted programming language. It emphasizes readability through the use of whitespace and supports multiple programming paradigms such as functional and object-oriented models.
File Input and Output
In Python, working with files starts with a single function, open().
The first parameter of open() is the file to open. After that is the mode of file access.
|open for reading (default)|
|open for writing, truncating the file first|
|open for exclusive creation, failing if the file already exists|
|open for writing, appending to the end of the file if it exists|
|text mode (default)|
|open a disk file for updating (reading and writing)|
To work with files, there are three different functions:
- read(): return one big string
- readline: return one line at a time
- readlines: returns a list of lines
For writing to files, there are two functions:
- write(): Save sequence of characters to a file
- writelines(): Save a list of strings.