Modules for files¶
Built-in modules¶
The Python standard library contains a number of built-in modules that you can use to manage files:
Module |
Description |
---|---|
performs common pathname manipulations |
|
manipulates pathnames |
|
iterates over multiple input files |
|
compares files and directories |
|
creates temporary files and directories |
|
use UNIX-like path and file name patterns |
|
randomly accesses lines of text |
|
performs higher level file operations |
|
Assignment of file names to MIME types |
|
enable Python object serialisation and persistence, see also The pickle module |
|
reads and writes CSV files |
|
JSON encoder and decoder |
|
provides a DB-API 2.0 interface for SQLite databases, see also The sqlite module |
|
|
reads and writes XML files, see also R:doc:../save-data/xml |
Parsing HTML and XHTML |
|
reads and writes Windows-like configuration files ( |
|
encodes/decodes files or streams |
|
reads and writes structured data to and from files |
|
for working with archive files and compressions |
pandas IO tools¶
Checks¶
What use cases can you imagine in which the
struct
module would be useful for reading or writing binary data?when reading and writing a binary file
when reading from an external interface, where the data should be stored exactly as it was transmitted
Why pickle may or may not be suitable for the following use cases:
Saving some state variables from one run to the next ✅
Storing evaluation results ❌, as pickle is dependent on the respective Python version
Saving user names and passwords ❌, as pickles are not secure
Saving a large dictionary with English terms ❌, as the entire pickle would have to be loaded into memory