Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

pyextract

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.

About

A nullsafe-like function for Python that can be used to extract data from dicts, lists, etc.

Resources

License

Releases

No releases published

Packages

No packages published

Languages