Skip to main content

Dot notation python dicationary

Project description

pydotmap

built with Python3

This package is just a wrapper to python standard library dict and OrderedDict from pythoncollections library with support of pickling and unpickling. 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

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

pydotmap-0.0.7.tar.gz (2.7 kB view hashes)

Uploaded Source

Built Distribution

pydotmap-0.0.7-py3-none-any.whl (3.9 kB view hashes)

Uploaded Python 3

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