Skip to main content

TThe versatile dict for Python!

Project description

Folder Dict

The versatile dict for Python!

Installation

pip install folder-dict

or clone this repository and run the following command.

pip install -e ./

Import

from folder_dict import FolderDict

Usage

  • Import and Construct

    # Empty Folder Dict
    fd = FolderDict(sep="/")
    > fd
    --> FolderDict({})
    
  • Subscription

    user =  {
        "name": "Joe",
    	"age": 22,
    	"hobbies": ["Playing football", "Podcasts"],
        "friends": {
    		"Sue": {"age": 30},
        	"Ben": {"age": 35},
    	    }
    }
    
    fd = FolderDict(user, sep="/")
    > fd["name"]
    --> Joe
    
    > fd["friend/Sue/age"]
    --> 30
    
    > fd["/friend/Ben"]
    --> FolderDict({
        "age": 30,
    })
    
    • Multiple inputs
      > fd["name", "age","friends/Ben/age"]
      --> ("Joe", 22, 35)
      
  • Assignment
    Assigns the object at the given path into the FolderDict.

    fd = FolderDict(sep="/")
    fd["path/to/obj_name"] = 10
    
    > fd["path/to/obj_name"]
    10
    
    • Multiple inputs
    fd["a/b", "c/d"] = (0,1)
    > fd
    --> FolderDict({
        "a/b": 0,
        "c/d": 1
    })
    
  • list Lists all paths contained in the FolderDict.

    fd["a/b", "c/d"] = (0,1)
    > fd.list()
    --> ["/a/b", "/c/d"]
    
  • Direct card ~
    Get paths ending with "c".

    fd["a/b/c", "d/e/f/abc", "g/h/c", "i/j"] = (1,2,3,4)
    > fd.list("~c")
    --> ["/a/b/c", "/d/e/f/abc", "/g/h/c"]
    

    cf.

    > fd.list("~/c")
    --> ["a/b/c", "g/h/c"]
    
  • Properties

    fd["a/b","a/c"] = (1,2)
    
    # dict
    > fd.dict
    --> {'a': {'b': 1, 'c': 2}}
    
    # PathDict
    > fd.PathDict
    -->PathDict({
      "a": {
        "b": 1,
        "c": 2  
      }
    })
    
    # sep
    > fd.sep
    --> '/'
    

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

folder_dict-0.1.2.tar.gz (5.0 kB view hashes)

Uploaded Source

Built Distribution

folder_dict-0.1.2-py3-none-any.whl (4.8 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