Dot notation python dicationary
Project description
pydotmap
This package is just a wrapper to python standard library dict
and OrderedDict
from pythoncollections
library with support of pickling and unpickling. It will also make you able to use decorator that will save your time to convert dict definition param to pydotmap. It will allow you to use python dict or dictionary as dot notation just like javascript object.
How to initialize?
author = DotMap(name="Atul", sirname="Singh")
Or
from pydotmap import DotMap
author = DotMap()
author.name = "Atul"
author.sirname = "Singh"
How to use?
from pydotmap import DotMap
from pydotmap import OrderedDotMap
author = DotMap(name="Atul", sirname="Singh", addr=["country": "India"])
print(author.name)
print(author.sirname)
del author.sirname
print(author.sirname)
print(author.get("sirname", "singh")) # you can use your default value same as dict
print(author.addr[0].country)
# Ordered Map - This will maintain the order of your dictionary
author = OrderedDotMap(name="atul", sirname="singh", addr=[{"country": "India"}])
print(author)
You can pickle it also. How?
from pydotmap import DotMap
import pickle
author = DotMap(name="Atul")
print(pickle.dumps(author))
OUTPUT
b'\x80\x04\x952\x00\x00\x00\x00\x00\x00\x00\x8c\x0epydotmap.pymap\x94\x8c\x06DotMap\x94\x93\x94)\x81\x94\x8c\x04name\x94\x8c\x04Atul\x94sh\x03b.'
you can use OrderedDotMap same way as DotMap to create pickle dump
How to use pydotmap decorator?
from pydotmap import dotmap
value = {"author": "atul"}
@dotmap
def check_decorator(in_value):
return in_value.author
print(check_decorator(value))
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
pydotmap-0.0.9-py3.8.egg
(5.6 kB
view details)
File details
Details for the file pydotmap-0.0.9-py3.8.egg
.
File metadata
- Download URL: pydotmap-0.0.9-py3.8.egg
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1852fc0cc7054044957b2e56b2e0837292074c7dfa61e63f6accb64f3d6d1995 |
|
MD5 | badccdb68e84e7e38e0afe18a326e3eb |
|
BLAKE2b-256 | 9e9fe1f8e60c6d5171a353ef43e28bd31c5fe9e095ed90f85ddc050e933751f5 |