Library for convert N-level dictionaries to one-level dictionaries
Project description
Multi-purposes conversors for Python
Installation
Use the package manager pip to install general-conversors.
pip3 install general-conversors
Usage
To 1-Level dictionary
from conversor.dict import ToOneLevel
source = {
'error': False,
'result': {
'executed': True,
'payload': 'Hello world',
'code': 200,
'source_code_url': 'http://google.com'
}
}
## replace_underscore as True
conversor = ToOneLevel(source=source, replace_underscore=True)
result = conversor.convert()
print('Result replacing underscore:', result)
# Result replacing underscore: {'error': False, 'result.executed': True, 'result.payload': 'Hello world', 'result.code': 200, 'result.source.code.url': 'http://google.com'}
## replace_underscore as False (Default)
conversor = ToOneLevel(source=source)
result = conversor.convert()
print('Result:', result)
# Result: {'error': False, 'result.executed': True, 'result.payload': 'Hello world', 'result.code': 200, 'result.source_code_url': 'http://google.com'}
To N-level level dictionary
from conversor.dict import ToMultiLevel
source = {
'error': False,
'result.executed': True,
'result.payload': 'Hello world',
'result.code': 200
}
conversor = ToMultiLevel(source=source)
result = conversor.convert()
print('Result:', result)
# Result: {'error': False, 'result': {'executed': True, 'payload': 'Hello world', 'code': 200}}
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
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
Built Distribution
File details
Details for the file general-conversors-1.0.8.tar.gz
.
File metadata
- Download URL: general-conversors-1.0.8.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95139f9379b64d0c3bfe3deea26192f311ba6e9aaa24a667789076c00d3ab945 |
|
MD5 | 8244a683cc1c6f5baa6f8bfed4f04e17 |
|
BLAKE2b-256 | 503058e799a5f4e64714765425d162d43be1776526de29f08071406b4e8ed49d |
File details
Details for the file general_conversors-1.0.8-py3-none-any.whl
.
File metadata
- Download URL: general_conversors-1.0.8-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f30a7a9a3165d33efe07e8a8a7568509ada578299da6e057d10c25c932bb051 |
|
MD5 | 273a4b0fca39c73272f1dab0dc5278db |
|
BLAKE2b-256 | 0cce22b5e9802761861b2cf7614327014e27c385233025e672d11548c05b39f8 |