Summary
In this chapter, we have explored working with files and directories. We have learned how to open files for reading and writing and how to do that more 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.
And finally, we saw how to persist data using pickle
, shelve
, and the SQLAlchemy ORM library.
You should now have a pretty good idea of how to deal with files and data persistence...