Python Utils is a module with some convenient utilities not included with the standard Python install
Project description
Python Utils is a collection of small Python functions and classes which make common patterns shorter and easier. It is by no means a complete collection but it has served me quite a bit in the past and I will keep extending it.
One of the libraries using Python Utils is Django Utils.
Documentation is available at: http://python-utils.readthedocs.org/en/latest/
Links
The source: https://github.com/WoLpH/python-utils
Project page: https://pypi.python.org/pypi/python-utils
Reporting bugs: https://github.com/WoLpH/python-utils/issues
Documentation: http://python-utils.readthedocs.io/en/latest/
My blog: https://wol.ph/
Requirements for installing:
six any recent version
Installation:
pip install python-utils
Quickstart
This module makes it easy to execute common tasks in Python scripts such as converting text to numbers and making sure a string is in unicode or bytes format.
Examples
To extract a number from nearly every string:
from python_utils import converters
number = converters.to_int('spam15eggs')
assert number == 15
number = converters.to_int('spam')
assert number == 0
number = converters.to_int('spam', default=1)
assert number == 1
number = converters.to_float('spam1.234')
To do a global import programmatically you can use the import_global function. This effectively emulates a from … import *
from python_utils.import_ import import_global
# The following is the equivalent of `from some_module import *`
import_global('some_module')
Or add a correclty named logger to your classes which can be easily accessed:
class MyClass(Logged):
def __init__(self):
Logged.__init__(self)
my_class = MyClass()
# Accessing the logging method:
my_class.error('error')
# With formatting:
my_class.error('The logger supports %(formatting)s',
formatting='named parameters')
# Or to access the actual log function (overwriting the log formatting can
# be done n the log method)
import logging
my_class.log(logging.ERROR, 'log')
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 Distribution
Hashes for python_utils-2.0.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 670f9b992ebfc005329fd9740408f2a704e595d64c8f8da83f7977618dba4acc |
|
MD5 | dcf70d4b5b14b9aa8475e01c64adb81b |
|
BLAKE2b-256 | a6d9b0b61984fa66ec63d9510d10e1bdf20a2314110f37e5e0fd036bc97befdd |