Helper module for creating simple Python 3 scripts
Project description
scripthelper
Helper module for simple command line Python scripts
Basic usage
import scripthelper
logger = scripthelper.bootstrap()
logger.critical('critical message')
logger.error('error message')
logger.warning('warning message')
logger.info('info message')
logger.verbose('verbose message')
logger.debug('debug message')
logger.spam('spam message')
It just works, and adds --verbose
and --quiet
command line options, too.
Adding other command line parameters
import scripthelper
scripthelper.add_argument('-n', '--name', help='Name to greet')
logger, args = scripthelper.bootstrap_args()
if args.name:
logger.debug('Name was provided')
logger.info(f'Hello {args.name}')
else:
logger.warning('Name was not provided')
Progressbar works with logging, too
import scripthelper
import time
logger = scripthelper.bootstrap()
logger.info('Doing the calculations...')
for i in scripthelper.progressbar(range(200)):
if i % 20 == 0:
logger.verbose(f'Iteration {i}')
if i % 5 == 0:
logger.debug(f'Iteration {i}')
logger.spam(f'Iteration {i}')
time.sleep(0.05)
logger.info('Done')
You can easily preserve logs in files
import scripthelper
logger = scripthelper.bootstrap()
scripthelper.setup_file_logging()
logger.warning('warning message')
logger.info('info message')
logger.debug('debug message')
It handles exceptions, warnings
import scripthelper
import warnings
scripthelper.bootstrap()
warnings.warn("This user warning will be captured.")
raise RuntimeError("This exception should be handled.")
(The local variables will be displayed in stack trace.)
Has built-in colored pretty printer
something = {
"bool": True,
"none": None,
"integer": 1234,
}
scripthelper.pp(something)
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
scripthelper-1.9.tar.gz
(4.0 kB
view hashes)
Built Distribution
Close
Hashes for scripthelper-1.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bee85b8bf18dfc3c4c47ecdab503e57af79a968d681df19c675dbd231d6768ca |
|
MD5 | 4bdbaadbc90edbbe01e37138714fa867 |
|
BLAKE2b-256 | 67e0ebb7a5e85e25a0628444c7d0152d06b526b38bee90b483a3642fe00f3d1d |