Skip to main content

A very simple module to safely save data to files in python

Project description

A very simple module to safely save data to files in python.

When you choose a path and a name for the file you want to save your data to, the script checks if the given file at the given path already exist; if so, it adds an increasing numbering at the end of the file name (just before the file extension if there is any) untill it finds a path+name not taken already.

This prevents from losing data by inadvertently re-writing a file.

Install

$ pip install save

Basic usage

from save import save

data = 'Hey there'
save(data, 'my_file.txt')

The safe_path function

You can import the safe_path submodule to use with other libraries or functions. It provides the same functionality as save(). (Basically the save() function itself calls safe_path() to do the work)

This is an example involving matplotlib:

from matplotlib import pyplot as plt
from save import safe_path

plt.plot(range(10))
plt.savefig(safe_path('my_figure.png'))

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

save-0.1.tar.gz (2.6 kB view details)

Uploaded Source

File details

Details for the file save-0.1.tar.gz.

File metadata

  • Download URL: save-0.1.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for save-0.1.tar.gz
Algorithm Hash digest
SHA256 5b93591b8c0b3e37a715eaaf120eecaf9fd7b8580f45f8d018fefa41bb3eb1eb
MD5 62a1d7b0db88cdb133117fd6af346026
BLAKE2b-256 18004c699e5d2d19712bdb014b1aea3bfaeff757257e6ee9f405a388779735e7

See more details on using hashes here.

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