Skip to main content

Enginering useful library

Project description

Open Kage's useful tools and class to public. (Long time used and upgraded) But, this is develope version. So, suddenly it will be big change when I got some more good idea. I re-groupped to library. and change name to klib

Custom Dictionary Class

Convert Dictionary to Object style Dictionary

Contents

  1. Create tree type items
  2. Added New commands
    1. Put() : Put value at a item
    2. Get() : Get value of item
    3. Del() : Delete item
    4. Update() : Update value at item
    5. Print() : Print dictionary
    6. Diff() : Compare two dictionary
    7. Check() : Check put the value is same as the item(key)'s value
    8. List() : Return list of keys value
    9. Proper() : Show/Set/Update property at the item.
    10. Find() : Find data in the dictionary
    11. Load() : Load saved data from file
    12. Save() : dictionary save to file
    13. Sort() : Sort dictionary
    14. FirstKey(): Get first Key
  3. Added property at each key
  • Initialize dictionary
from DICT import DICT
root=DICT()

or

import DICT
root=DICT.DICT()
from DICT import DICT
>>> test={
      'a':123,
      'b':{
         'c':{'ddd'},
         'e':{}
      }
    }
root=DICT(test)

or

from DICT import DICT
>>> root=DICT()
  • Add new data
>>> root.tree.apple.color='red'

or

>>> root.tree.apple.Put('color','red')

or

>>> root.tree.apple['color']='red'
  • Get data
>>> root.tree.apple.color.Get()

or

>>> root.tree.apple.Get('color')
  • Print dictionary
>>> root.Print()
>>> root.tree.Print()
  • Set property at Apple's color

    • Set readonly
>>> root.tree.apple.color.Proper('readonly',True)
  • Try change data
>>> root.tree.apple.Put('color','white')
item is readonly

>>> root.tree.Print()
{'color': {'._d': 'red', '._p': {'readonly': True}}}
  • Unset readonly
>>> root.tree.apple.color.Proper('readonly',False)
  • Try change data
>>> root.tree.apple.Put('color','white')
>>> root.tree.Print()
{'color': {'._d': 'red', '._p': {'readonly': True}}}

Sample Dictionary:

{'a': 123,
 'b': {'c': set(['ddd']), 'e': {}, 'z': 123},
 'tree': {'apple': {'color': {'._d': 'white', '._p': {'readonly': False}}},
          'banana': {'banana2': {'._d': 'white', '._p': {}},
                     'banana3': {'._d': 'yellow', '._p': {}},
                     'color': {'._d': 'yellow', '._p': {'readonly': True}}},
          'yellow': {'monkey': {'._d': 'white', '._p': {}}}}}
  • Find readonly property item path
>>> root.Find('readonly',property=True)
['tree/banana/color']
  • Find apple key path
>>> root.Find('apple',mode='key')
['tree/apple']
  • Find white color data path
>>> root.Find('white')
['tree/apple/color', 'tree/yellow/monkey', 'tree/banana/banana2']
  • Find 123 data path
>>> root.Find('white')
['a', 'b/z']
  • Find white color data path in key and value
>>> root.Find('yellow',mode='all')
['tree/yellow', 'tree/banana/color', 'tree/banana/banana3']
  • Save Data (always use root if not then save partial data)
>>> from DICT import DICT
>>> DICT._dfile_='<dict file name>'
>>> root.Save()

or

>>> import DICT
>>> DICT.DICT._dfile_='<dict file name>'
>>> root.Save()
  • Load Data (always use root if not then load at key)
>>> from DICT import DICT
>>> DICT._dfile_='<dict file name>'
>>> root.Load()

or

>>> import DICT
>>> DICT.DICT._dfile_='<dict file name>'
>>> root.Load()

MISC functions

Useful commands

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

kmisc-2.1.10.tar.gz (98.1 kB view hashes)

Uploaded Source

Built Distribution

kmisc-2.1.10-py3-none-any.whl (114.6 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