Commonly Consumed Code Commodities
Project description
Commonly Consumed Code Commodities
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for reusables-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5d395cf98b922f5863d5d9a7a500c63a75b73650d1f4063009afe59cdfe0460 |
|
MD5 | c80f699760797f9a66becacad17af1d3 |
|
BLAKE2b-256 | 8275a8d9552930174dd898d67a63102326c93b4ec94edad8c8f4b93a652db430 |
Hashes for reusables-0.2.0-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7c81742f65fe096987e76f92b21d7ba3ce6aae6b91dd4661c520fd1fab39aa9 |
|
MD5 | 6cb48b3b9f165de22550744bbb9dd6c3 |
|
BLAKE2b-256 | 88f250caa7c1d6023571b9380ca7de319db2ecab48a093e82ca9cb69394c00d8 |