io: Generic I/O support¶
Convenience routines for opening/saving files while handling compression suffixes, tilde (~) expansion, environment variable expansion, etc.
- open_input(source, encoding=None, *, compression=None)¶
Supported API . Open possibly compressed input for reading.
source can be path or a stream. If a stream, it is simply returned. encoding is the same as for Python’s builtin ‘open’ command, so None means binary and typically ‘utf-8’ is used for text. If compression is None, whether to use compression and what type will be determined off the file name.
Also, if source is a string that begins with “http:” or “https:”, then it is interpreted as an URL. Determining the encoding of the data returned by the URL is attempted by examining Content-Encoding and/or Content-Type headers, but if those are missing then encoding is used instead (binary if encoding is None).
- open_output(output, encoding=None, *, append=False, compression=None)¶
Supported API . Open output for (possibly compressed) writing.
output can be path or a stream. If a stream, it is simply returned. encoding is the same as for Python’s builtin ‘open’ command, so None means binary and typically ‘utf-8’ is used for text. If compression is None, whether to use compression and what type will be determined off the file name.