skip to navigation
skip to content

Not Logged In

reusables 0.2.0

Commonly Consumed Code Commodities

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

 
File Type Py Version Uploaded on Size
reusables-0.2.0-py2-none-any.whl (md5) Python Wheel 2.7 2014-05-15 15KB
reusables-0.2.0-py2.6.egg (md5) Python Egg 2.6 2014-05-15 31KB
reusables-0.2.0-py2.7.egg (md5) Python Egg 2.7 2014-05-15 31KB
reusables-0.2.0-py3-none-any.whl (md5) Python Wheel 3.4 2014-05-15 15KB
reusables-0.2.0-py3.2.egg (md5) Python Egg 3.2 2014-05-15 31KB
reusables-0.2.0-py3.3.egg (md5) Python Egg 3.3 2014-05-15 32KB
reusables-0.2.0-py3.4.egg (md5) Python Egg 3.4 2014-05-15 32KB
reusables-0.2.0.tar.gz (md5) Source 2014-05-15 13KB
  • Downloads (All Versions):
  • 41 downloads in the last day
  • 268 downloads in the last week
  • 866 downloads in the last month