Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Ruby's OpenStruct for python

Project description

License: MIT codecov Build Status Python 3.7

PyDapt

PyDapt coverts a dictionary into an object. It is similar to the OpenStruct of ruby.

Installation

Python Version Required >= 3
pip install pydapt

Usage

Converting a dictionary to Object

from pydapt.models import PyFlex

dictionary = {"test": 1, "test1": {"test2": 2}}
pyflex = PyFlex(dictionary)

print(pyflex.test) # 1
print(pyflex.test1.test2) # 2

Converting a dictionary to Object with kwargs

from pydapt.models import PyFlex

dictionary = {"test": 1, "test1": {"test2": 2}}
pyflex = PyFlex(dictionary, test3=3, test4=4)

print(pyflex.test) # 1
print(pyflex.test1.test2) # 2
print(pyflex.test3) # 3
print(pyflex.test4) # 4

Deleting an attribute

from pydapt.models import PyFlex

dictionary = {"test": 1, "test1": {"test2": 2}}
pyflex = PyFlex(dictionary)

print(pyflex.test) # 1
print(pyflex.test1.test2) # 2

pyflex.drop('test3') # None
pyflex.drop('test') # 1

print(pyflex.test) # AttributeError: 'PyFlex' object has no attribute 'test'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pydapt, version 0.3
Filename, size File type Python version Upload date Hashes
Filename, size pydapt-0.3.tar.gz (3.5 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page