`writer-cm` is a context manager allowing you to atomically write files given a file path.
Project description
writer-cm
is a context manager allowing you to atomically write files given a
file path.
Features
- Cross-platform atomic file writes powered by python-atomicwrites.
- Interface using a file path instead of a file handle, for more compatibility
with external libraries (e.g.
pandas.to_pickle
). - Automatically create missing directories and set their permissions.
- Automatically set the file permissions.
Installation
pip install writer-cm
Usage
from writer_cm import writer_cm
with writer_cm("file.txt") as temp:
with open(temp, mode="w") as fh:
fh.write("foo")
with open("file.txt") as fh:
assert fh.read() == "foo"
Pass overwrite=True
to overwrite an already existing file; an error is thrown otherwise:
with writer_cm("file.txt", overwrite=True) as temp:
with open(temp, mode="w") as fh:
fh.write("bar")
with open("file.txt") as fh:
assert fh.read() == "bar"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
writer-cm-1.0.6.tar.gz
(2.9 kB
view hashes)
Built Distribution
Close
Hashes for writer_cm-1.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39ee1a0bebb9b88e253dcac647995d80569f5e80a1a3822b1d1f4f999dbdd62a |
|
MD5 | 05e043b53e368b726a7f1c0324d50363 |
|
BLAKE2b-256 | bfad6f9bb6768dad925cd40e571fdad5a8e76a8787dbb847a001220d895cea1a |