dukepy
collection of useful python snippets
pip install dukepy
config
Confiuration manager (using json) with the ability to
- add new keys
- remove deprecated keys (i.e. keys not in defaults)
- backup the older versions of the (json) configuration file
Generated sample file -
C:\Users\xyz.myconfig\config.json
{
"newkey1": "newvalue1",
"newkeygroup1": {
"newkey2": "newvalue2"
},
"newkey3": [
"newvalue4",
"newvalue4"
],
"newkey5": "newvalue5"
}
Usage example -
import os
from dukepy.config import Config
config_dir = os.path.join(os.path.expanduser("~"), ".myconfig")
config_file = os.path.join(config_dir, "config.json")
Config(path=config_file, defaults={
"newkey1": "newvalue1",
"newkeygroup1": {
"newkey2": "newvalue2"
},
"newkey3": ["newvalue4", "newvalue4"]
})
Config()["newkey5"] = "newvalue5"
Config().commit()
converge
To find the extremes of a finite sequence, given that the sequence is continuous. Provide at least two known numbers in the sequence, and a method to check the validity of the number predicted by the algorithm.
Usage example -
def check_validity(val):
if val > -30 and val < 101:
return True
else:
return False
low, high = Converge(-28, 50, check_validity).run()
print(low)
print(high)
Output -
-29
100
dict_diff
- To find the recursive differences between two dictionaries.
- To update one dictionary with the other (each one optional)-
- Add keys from the other
- Remove keys which are not part of the other
- Update values from the keys of the other
Usage example -
dictionary_1 = {"abc": "value_abc",
"prs": "value_prs"}
dictionary_2 = {"abc": "value_abc",
"xyz": "value_xyz"}
dict_diff(dictionary_1, dictionary_2)
print(dictionary_1)
print(dictionary_2)
dict_diff(dictionary_1, dictionary_2,
udpate_added_keys=True)
print(dictionary_1)
print(dictionary_2)
Output -
:
- prs : value_prs
:
+ xyz : value_xyz
{'abc': 'value_abc', 'prs': 'value_prs'}
{'abc': 'value_abc', 'xyz': 'value_xyz'}
:
- prs : value_prs
:
+ xyz : value_xyz
{'abc': 'value_abc', 'prs': 'value_prs', 'xyz': 'value_xyz'}
{'abc': 'value_abc', 'xyz': 'value_xyz'}
logger
mail_bot
safe_dict
singleton
taces
Prints the origin of the exception, not just the exception string. Usage example -
mydict = dict()
try:
print(mydict["sdf"])
except Exception as e:
print_exception_traces(e)
Output -
Traceback (most recent call last):
File "C:/Dev/libpython/src/dukepy/traces.py", line 16, in <module>
print(mydict["sdf"])
KeyError: 'sdf'
Release files for dukepy 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dukepy-1.3.0.tar.gz | 17.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dukepy-1.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 38.9 kB
Release files / dukepy-1.3.0.tar.gz
| Download URL | dukepy-1.3.0.tar.gz |
|---|---|
| Size | 17.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6c92b93d353e1fddf6ae59d1e77653946da535416f0695da6f71367f5062463c
|
|
BLAKE2b-256 checksum How to use checksums |
2928bf95262b49dbd1407444c5aec16f203979f2682aafda801ed0df88f95098
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6
|
Release files / dukepy-1.3.0-py3-none-any.whl
| Download URL | dukepy-1.3.0-py3-none-any.whl |
|---|---|
| Size | 21.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
34027be43d9ac6523b7aac09ff2cf46d6a12b8f89eacfea9cc6f6797db6b2aa9
|
|
BLAKE2b-256 checksum How to use checksums |
8de6c966ab0248c384c4dd13d52d5b4c5847404d87577bff84ec93de8457d681
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6
|