[PYTHON] I tried using easydict (memo).

You will be able to access the elements of the dictionary with dots. Like this.

d = edict({'foo':3, 'bar':{'x':1, 'y':2}})
print d.foo
print d.bar.x
#Output 3
#Output 1

I tried it on windows7 (python 2.7 series).

It is here. https://github.com/makinacorpus/easydict Play with the readme here.

Installation python setup.py install easy_install easyjson Add it in the meantime.

An error occurs when Japanese is entered in the key. Error even if quoted. At some point, this might be possible ... Japanese can be used for the value.

Could as be used like this ... EasyDict of readme seems to be useless in this case unless it is all edict.

test code

from easydict import EasyDict as edict
from simplejson import loads
#from prettyprint import pp

d = edict({'foo':3, 'bar':{'x':1, 'y':2}})

print d.foo
print d.bar.x

#Output 3
#Output 1

j = """{
        "Buffer": 12,
        "name":"Allegra",
        "List1": [
            {"type" : "point", "coordinates" : [100.1,54.9] },
            {"type" : "point", "coordinates" : [109.4,65.1] },
            {"type" : "point", "coordinates" : [115.2,80.2] },
            {"aaa" : "point", "coordinates" : [150.9,97.8] }
          
                ]
    }"""
d = edict(loads(j))
print d.Buffer
print d.name
print d.List1[0].coordinates[1]
print d.List1[3].aaa
#pp(d)

#Output 12
#Output Allegra
#Output 54.9
#Output point

b = edict()
b.debug = True
b.foo = 7
b.zzz = u"Gundam"

print b.items()

#output[('debug', True), ('foo', 7), ('log', False), ('zzz', u'\u30ac\u30f3\u30c0\u30e0')]
#Output Gundam

class Flower(edict):
     power = 1

f = Flower({'height': 12})
print f.power
print f['power']
print f.items()

#Output 1
#Output 1
#output[('power', 1), ('height', 12)]

Recommended Posts

I tried using easydict (memo).
I tried using parameterized
I tried using argparse
I tried using mimesis
I tried using anytree
I tried using aiomysql
I tried using Summpy
I tried using coturn
I tried using Pipenv
I tried using matplotlib
I tried using "Anvil".
I tried using Hubot
I tried using ESPCN
I tried using openpyxl
I tried using Ipython
I tried using PyCaret
I tried using cron
I tried using ngrok
I tried using face_recognition
I tried using Jupyter
I tried using PyCaret
I tried using Heapq
I tried using doctest
I tried using pipenv, so a memo
I tried using folium
I tried using jinja2
I tried using folium
I tried using time-window
[I tried using Pythonista 3] Introduction
I tried face recognition using Face ++
I tried using Random Forest
I tried using BigQuery ML
I tried using Amazon Glacier
I tried using git inspector
[Python] I tried using OpenPose
I tried using magenta / TensorFlow
I tried using AWS Chalice
I tried using Slack emojinator
I tried using Rotrics Dex Arm # 2
I tried using Rotrics Dex Arm
I tried using GrabCut of OpenCV
I tried using Thonny (Python / IDE)
I tried server-client communication using tmux
I tried reinforcement learning using PyBrain
I tried deep learning using Theano
Somehow I tried using jupyter notebook
[Kaggle] I tried undersampling using imbalanced-learn
I tried shooting Kamehameha using OpenPose
I tried using the checkio API
[Python] I tried using YOLO v3
I tried asynchronous processing using asyncio
I tried using Amazon SQS with django-celery
I tried using Azure Speech to Text.
I tried using Twitter api and Line api
I tried scraping
I tried PyQ
I tried using YOUTUBE Data API V3
I tried using Selenium with Headless chrome
I tried drawing a line using turtle
[Kaggle] I tried ensemble learning using LightGBM
I tried using PyEZ and JSNAPy. Part 2: I tried using PyEZ