Skip to content
This repository has been archived by the owner on Jan 22, 2019. It is now read-only.

DictObject

Christian Cuevas edited this page Apr 26, 2017 · 16 revisions

What is DictObject?

DictObject is a class within gamelocker which converts a python dictionary into a object.

How It Works

To Call DictObject Directly:

   >>> gamelocker.DictObject(dictionary)

To Convert A Dictionary To A Object From Within Another gamelocker Class:

   >>> api = gamelocker.Vainglory(vg_api_key) # Create the instance of the class<br>
   >>> data = api.dict_to_object(dictionary) # Convert a dictionary to a object

Example:

The DictObject class would turn the following dictionary into an object:

   >>> {"id": "123456789", "name": "ClarkthyLord", "region": "na", "titles": ["developer", "creator"], "extra": {"likes": "vainglory", "dislikes": "pain"}}

Uses

Tired of having to type ["key_name"] every time you want to retrieve data from a dictionary?
Then the DictObject class is perfect for you! Turning that dictionary into an object can save you the trouble of typing the [""]

Retrieving A Simple Value

  • Before
   >>> data["name"]
  • After
   >>> data.name

Retrieving A Value From A List

  • Before
   >>> data["titles"][1]
  • After
   >>> data.titles[1]

Retrieving A Value From A Dictionary

  • Before
   >>> data["extra"]["likes"]
  • After
   >>> data.extra["likes"]

Notice

DictObject is still in testing; use at your own risk!

Clone this wiki locally