Skip to main content

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


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)

Uploaded Source

Built Distribution

safer-0.9.5-py3-none-any.whl (7.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page