Skip to content
Python library for SGOL (Spatial Graph Operations Language)
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
sgol
.gitignore
.travis.yml
AUTHORS
CONTRIBUTING.rst
LICENSE
MANIFEST.in
README.rst
requirements.txt
setup.cfg
setup.py

README.rst

sgol-python

https://travis-ci.org/spatialcurrent/pyextract.png Master Documentation Status

Description

This repo contains a nullsafe-like function for Python that can be used to extract data from dicts, lists, etc.

Installation

Install via PyPI with:

pip install pyextract

Or install directly from GitHub with:

pip install git+git://github.com/spatialcurrent/pyextract.git@master

Usage

The position args are keyChain, node, and fallback. If the keyChain is invalid, then the fallback value is returned. The fallback is only returned if (1) the location described by the keyChan is invalid or (2) the value located is None. If the value located is a blank string, zero, false, etc., then it will return. If handling for blank strings, then use the 3rd pattern below to fallback even if the value found is a blank string.

from pyextract.extract import extract

x = { "a": {"b": "c"} }
y = extract(["a", "b"], x, None)
# y == c

x = { "a": {"b": None} }
y = extract(["a", "b"], x, None)
# y == None

x = { "a": {"b": None} }
y = extract(["a", "b"], x, "") or "c"
# y == c

Contributing

Spatial Current, Inc. is currently accepting pull requests for this repository. We'd love to have your contributions! Please see Contributing.rst for how to get started.

License

This work is distributed under the MIT License. See LICENSE file.

You can’t perform that action at this time.