Skip to main content

No project description provided

Project description

prodot

A new way to deal with dictionaries and lists in python.

install

pip install prodot

Usage

Import the dot object from the prodot library. You can create a new empty dictionary, or start with a filled one

from prodot import DotObject

# No parameters instances an empty dictionary
my_new_obj = DotObject() 

# The Dot Object can be initialized with a dictionary
my_dict_obj = DotObject({"foo":["bar,"eggs"]})

# The Dot Object can also initialize with a list
my_list_obj = DotObject([ [1,2,3], ["a","b","c"], [{"foo":"bar"}, {"bar":"eggs"}] ])

Dot notation usage

By using the dot-object you can use the dictionary as a class

my_json = {
  "userData": {
    "name": "John",
    "age": "38",
    "shoppingCart": [
      {"cellphone": 999.99},
      {"notebook": 2999.99},
      {"wireless keyboard": 299.99}
    ]
  }
}

my_new_obj = DotObject(my_json)

shoppingCart = my_new_obj.userData.shoppingCart

The DotObject will return another instance of the DotObject with the main_object attribute as being the selected path.

>>> type(shoppingCart)
<class 'prodot.dot_object.DotObject'>

To get the brute value of the object, you can use the .get_value() function.

>>> shoppingCart.get_value()
[{"cellphone": 999.99}, {"notebook": 2999.99}, {"wireless keyboard": 299.99}]

# or by using the get_value directly at the path
>>> my_new_obj.userData.shoppingCart.get_value()
[{"cellphone": 999.99}, {"notebook": 2999.99}, {"wireless keyboard": 299.99}]

>>> type(shoppingCart.get_value())
<class 'dict'>

You can also add new information to the instancied object

# n3 means list index 3 (will be added as 4th item)
>>> my_new_obj.userData.shoppingCart.n3 = {"monitor": 699.99}
>>> my_new_obj.userData.shoppingCart.get_value()
[{"cellphone": 999.99}, {"notebook": 2999.99}, {"wireless keyboard": 299.99}, {"monitor": 699.99}]

Python doesn't accept list indexes to be used as a class attribute. For solve this problem, list indexes start with the n letter (like n0, n1, ...)

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

prodot-0.1.2.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

prodot-0.1.2-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file prodot-0.1.2.tar.gz.

File metadata

  • Download URL: prodot-0.1.2.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.10.6 Linux/5.15.79.1-microsoft-standard-WSL2

File hashes

Hashes for prodot-0.1.2.tar.gz
Algorithm Hash digest
SHA256 80ca76649eba39a1bfbde48c998dcc3df91baef849ed4fdca650f063a6bb7b5a
MD5 3e0e4b5be5482ce8cf11149183c3fe83
BLAKE2b-256 a1360837ff2f6bb8e2b321481d2d636089bf4eda7cdb31760d7fb19c7b4cc85b

See more details on using hashes here.

File details

Details for the file prodot-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: prodot-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.10.6 Linux/5.15.79.1-microsoft-standard-WSL2

File hashes

Hashes for prodot-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8f3890fcbcd9428d86f6219f2ca341eb7d3e78446bc49690eea364fe235ee5d3
MD5 f7f1bcbfbc0698eca5549ce2f09fbc12
BLAKE2b-256 9b8ac7b7bfb15739688dde1f840a7f609e184020ae15a3600a298acbdd07df26

See more details on using hashes here.

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