File I/O
We are discussing file I/O for two reasons:
- In the world of Linux operating systems, everything is a file. Interaction with peripherals on the Raspberry Pi is similar to reading from/writing to a file. For example: In Chapter 4, Communication Interfaces, we discussed serial port communication. You should be able to observe that serial port communication is like a file read/write operation.
- We use file I/O in some form in every project. For example: Writing sensor data to a CSVÂ file or reading pre-configured options for a web server, and so on.
Hence, we thought it would be useful to discuss file I/O in Python as its own chapter (detailed documentation available from here: https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files) and discuss examples where it could play a role while developing applications on the Raspberry Pi Zero.
Reading from a file
Let's create a simple text file, read_file.txt
with the following text: I am learning Python Programming using the...