Access python dicts using path strings (mainly just doing this to l2submodule)
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

1 ano atrás
12345678910111213141516171819202122
  1. A really simple library for accessing dictionary items using paths. Meant to make working with configuration files easier.
  2. ## quick-n-dirty documentalation
  3. The class you want is `confthing.Config(data, delimiter = "/", defaults = {}, requirements = [], **misc_options)`.
  4. - `data` is the dict you want to wrap the class around.
  5. - `delimiter` is whatever you want to use as a path delimiter.
  6. - `defaults` is a dict whose keys are paths and values are the default values for each path.
  7. - `requirements` is a list of paths that must be defined, otherwise MissingRequirementError is raised.
  8. - Miscellaneous options are as follows:
  9. - `strict_subscript`: when True, enables strict mode when getting items via subscript. Default is False.
  10. - `clobber_subscript`: when True, enables clobber mode when setting items via subscript. Default is False.
  11. ### Methods
  12. #### `get(path, fallback = None, strict = False)`
  13. Tries to return the value at the specified path, otherwise returns the fallback value (or raises PathNotFoundError if `strict` is True).
  14. #### `set(path, value, clobber = False)`
  15. Tries to set the value at the specified path. If it encounters an item that isn't a dict, it'll raise NotDictError if `clobber` is False, or it'll replace that with an empty dict.
  16. #### Subscripting
  17. Config objects are subscriptable, calling `get` and `set` as appropriate. The two `subscript` options control what `strict` and `clobber` are set to when subscripting.