A simple utility for working with JSON files.
Project description
jsonnote
A simple utility for working with JSON files.
Contains a small class jsonnote with the following attributes:
Properties:
filename - name of the file without the extension (extention '.json' will be added automatically).
location - location of the file. Once set, the file can be found and read from or write into.
contents - JSON contents of the class instance.
contents - JSON contents of the class instance.
Methods:
full_path()
file_exists()
*is_empty() - returns True/False depending on whether the contents of the class instance are empty
get_from_file() - reads contents from the JSON file
save_to_file() - saves contents in the JSON file
clear() - empties the contents
is_empty() - returns True/False depending on whether the contents of the class instance are empty
Examples of use:
>>> from jsonnote import jsonnote
>>> x=jsonnote()
>>> x.filename = 'temp'
>>> x.location
>>> x.location = '.'
>>> x.full_path()
'./temp.json'
>>> x.contents = {'fruits': ['apple', 'pear', 'orange'], 'veggies': ['potato', 'cucumber'], 'dairy': 'milk'}
>>> x.mustsave=True
>>> x.save_to_file()
>>> y=jsonnote()
destroy() - empties the contents and erases the file from the disc
reset() - empties the contents, destroys the file and sets 'filename' and 'location' to 'None'
Example of use:
>>> from jsonnote import jsonnote
>>> x=jsonnote()
>>> x.filename = 'temp'
>>> x.location
>>> x.location = '.'
>>> x.full_path()
'./temp.json'
>>> x.contents = {'fruits': ['apple', 'pear', 'orange'], 'veggies': ['potato', 'cucumber'], 'dairy': 'milk'}
>>> x.mustsave=True
>>> x.save_to_file()
>>> y=jsonnote()
>>> y.filename = 'temp'
>>> y.location='.'
>>> y.file_exists()
True
>>> y.contents
{'fruits': ['apple', 'pear', 'orange'], 'veggies': ['potato', 'cucumber'], 'dairy': 'milk'}
>>> y.contents['fruits'][1]
'pear'
>>> y.mustdelete=True # *False by default; if False the file is not deleted
>>> y.destroy()
>>> y.file_exists()
False
>>> y.contents
{}
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
File details
Details for the file jsonnote-0.13.tar.gz.
File metadata
- Download URL: jsonnote-0.13.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52027d45c70775f4bef34650c747c59a15e68d3e19d055d8633963476cee3abb
|
|
| MD5 |
0bbc983126e7ddf91c84ecb4f4e3c63e
|
|
| BLAKE2b-256 |
56c9ec8e796334e9798dc4395a13cac574cd16a8c47fda6ed72e62a391521a4d
|