Skip to main content

Commonly Consumed Code Commodities

Project description

Commonly Consumed Code Commodities Build Status Coverage Status

Overview

The reusables library is a reference of python functions and classes that programmers may find themselves often recreating.

Example

import reusables

reusables.config_dict('my_config.cfg')
# {'Section 1': {'key 1': 'value 1', 'key2': 'Value2'}, 'Section 2': {}}

reusables.safe_path('/home/user/eViL User\0\\/newdir$^&*/new^%file.txt')
# '/home/user/eViL User__/newdir____/new__file.txt'

reusables.find_all_files(".", ext=reusables.exts.pictures)
# ['/home/user/background.jpg', '/home/user/private.png']

Extras

Also included is a Namespace class, similar to Bunch but designed so that dictionaries are recursively made into namespaces, and can be treated as either a dict or a namespace when accessed.

from reusables import Namespace

my_breakfast = {"spam" : {"eggs": {"sausage": {"bacon": "yummy"}}}}
namespace_breakfast = Namespace(**my_breakfast)

print(namespace_breakfast.spam.eggs.sausage.bacon)
# yummy

print(namespace_breakfast.spam.eggs['sausage'].bacon)
# yummy

str(namespace_breakfast['spam'].eggs)
# "{'sausage': {'bacon': 'yummy'}}"

dict(namespace_breakfast.spam.eggs['sausage'])
# {'bacon': 'yummy'}

repr(namespace_breakfast)
# "<Namespace: {'spam': {'eggs': {'sausage': {'...>"

Additional Info

This does not claim to provide the most accurate, fastest or most ‘pythonic’ way to implement these useful snippets, this is simply designed for easy reference. Any contributions that would help add functionality or improve existing code is warmly welcomed!

Copyright (c) 2014 - Chris Griffith - MIT License

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

reusables-0.2.0.tar.gz (13.3 kB view hashes)

Uploaded Source

Built Distributions

reusables-0.2.0-py3.4.egg (33.2 kB view hashes)

Uploaded Source

reusables-0.2.0-py3.3.egg (33.4 kB view hashes)

Uploaded Source

reusables-0.2.0-py3.2.egg (32.5 kB view hashes)

Uploaded Source

reusables-0.2.0-py3-none-any.whl (15.7 kB view hashes)

Uploaded Python 3

reusables-0.2.0-py2.7.egg (32.1 kB view hashes)

Uploaded Source

reusables-0.2.0-py2.6.egg (32.2 kB view hashes)

Uploaded Source

reusables-0.2.0-py2-none-any.whl (15.7 kB view hashes)

Uploaded Python 2

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