Try to import all modules below a given root
Project description
Safely write or print to a file, leaving it unchanged if there’s an exception
Writes happen on a temporary file, which is only copied over the original file when the context completes successfully.
This means that safer will temporarily use as much disk space as the old file and the new file put together.
Example:
import safer
with safer.open(filename, 'w') as fp:
for line in source():
fp.write('this and that')
if CHANGED_MY_MIND:
# filename will be unchanged
raise ValueError
# or
with safer.printer(filename) as print:
print('this', 'and', 'that')
print('two', 'lines', sep='\n', end='\n---\n')
if CHANGED_MY_MIND:
# filename will be unchanged
raise ValueError
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
safer-0.9.5.tar.gz
(2.7 kB
view hashes)
Built Distribution
safer-0.9.5-py3-none-any.whl
(7.1 kB
view hashes)