On this page
lzma.open
Prev: lzma.LZMAFile | Up: lzma
Rel: lzma.compress, lzma.decompress, lzma.is_check_supported, lzma.LZMACompressor
Ref: docs.python.org — lzma.open
Tags: #public #python3 #stdlib #lzma
Import
import lzma
from lzma import open
Signature & Overview
lzma.open(filename, mode='rb', *, format=None, check=-1, preset=None, filters=None, encoding=None, errors=None, newline=None)
Open an LZMA-compressed file in binary or text mode.
Usage
import lzma
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as tmp:
p = Path(tmp) / "data.txt.xz"
with lzma.open(p, "wt", encoding="utf-8") as f:
f.write("hello xz")
with lzma.open(p, "rt", encoding="utf-8") as f:
assert f.read() == "hello xz"
Gotchas
- Default mode is binary (
"rb"): Pass"rt"/"wt"withencoding="utf-8"for text.
REPL Inspect
from lzma import open
help(open)
Linked from
Related notes
- tuts/python3/stdlib_module/lzma/LZMAFile Linked here; links to this page; shared tags: #lzma, #stdlib
- tuts/python3/stdlib_module/lzma Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/lzma/compress Linked here; shared tags: #lzma, #stdlib
- tuts/python3/stdlib_module/lzma/decompress Linked here; shared tags: #lzma, #stdlib
- tuts/python3/stdlib_module/lzma/is_check_supported Linked here; shared tags: #lzma, #stdlib
- tuts/python3/stdlib_module/lzma/LZMACompressor Linked here; shared tags: #lzma, #stdlib
- tuts/python3/stdlib_module/lzma/LZMADecompressor shared tags: #lzma, #stdlib
- tuts/python3/stdlib_module/lzma/LZMAError shared tags: #lzma, #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib