Skip to main content

Extended Dictionary

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. seperate to kDict from kmisc

Install

pip3 install kdic

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
    15. FirstKey(): Get first Key
  3. Added property at each key
  • Initialize dictionary
import kDict
root=kDict.kDict()
import kDict
>>> test={
      'a':123,
      'b':{
         'c':{'ddd'},
         'e':{}
      }
    }
root=kDict.kDict(test)
  • 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)
>>> import kDict
>>> kDict.kDict._dfile_='<dict file name>'
>>> root=kDict.kDict()
>>> root.Save()
  • Load Data (always use root if not then load at key)
>>> import kDict
>>> kDict.kDict._dfile_='<dict file name>'
>>> root=kDict.kDict()
>>> root.Load()

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

kdic-1.0.9.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kdic-1.0.9-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file kdic-1.0.9.tar.gz.

File metadata

  • Download URL: kdic-1.0.9.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.18

File hashes

Hashes for kdic-1.0.9.tar.gz
Algorithm Hash digest
SHA256 121f9695e0a6da57a53b9aa5201ff2085779e5aea7650a2c0fb28127b7de3b4b
MD5 2299f973f11934f99b1540df2398b358
BLAKE2b-256 579c5a3a4b477f47091e5d0ca7cfe76deb6fc4bf9e56e6df3ae15dd5f715f40a

See more details on using hashes here.

File details

Details for the file kdic-1.0.9-py3-none-any.whl.

File metadata

  • Download URL: kdic-1.0.9-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.18

File hashes

Hashes for kdic-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 5650d729d5b44144186e1268658546e4d41e1a57a0c7c8f9958783d7fd5bfcf1
MD5 b522784a18adede06b6f3314b5ae8a54
BLAKE2b-256 f1750eace8d7f52ba72a6ad10499a18600ea00a55651a671e6595bca83c7a54f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page