Summary
In this chapter, we explored working with files and directories. We learned how to read and write on files, and how to do that elegantly by using context managers. We also explored directories: how to list their content, both recursively and not. We also learned about paths, which are the gateway to accessing both files and directories.
We then briefly saw how to create a ZIP archive and extract its content. The source code of the book also contains an example with a different compression format: tar.gz
.
We talked about data interchange formats and have explored JSON in some depth. We had some fun writing custom encoders and decoders for specific Python data types.
Then we explored I/O, both with in-memory streams and HTTP requests.
We saw how to persist data using pickle
, shelve
, and the SQLAlchemy ORM library.
And finally, we explored two example of configuration files, using the INI and TOML formats.
You should now have a good understanding of how to deal with files and data...