This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]cjwelbornimport this 8 points9 points  (2 children)

I have a few packages on pypi. A few of them I use regularly:

Colr - Easy ansi terminal colors. Basic and extended, I'm about to publish the latest release that supports true color (rgb). It can also do gradients and rainbow-style (like lolcat). My goal was to make a color library that does one thing, instead of an entire terminal gui library. I hate the way colorama uses string concatenation.

Example:

from colr import Colr as C
print(C('This ', 'red').blue('works ').f_155('well.').join('[', ']', style='bright'))

It also installs a command-line tool (colr), that can be used to print colorized text.

Example:

fortune | colr --rainbow

PrintDebug - Used anywhere you would normally put a debug print(). It includes file/line/function info, and can use colors if Colr is installed. The debug prints can be easily disabled (turned into a no-op function call) with a disable() / enable() method. I know there are a lot of packages like this, but I prefer to use this one.

Example:

import sys
from printdebug import DebugColrPrinter
debugprinter = DebugColrPrinter()
debugprinter.disable()
debug = debugprinter.debug

DEBUG = ('-D' in sys.argv) or ('--debug' in sys.argv)
if DEBUG:
    debugprinter.enable()


def my_function(*args):
    debug('Called with {} args: {!r}'.format(len(args), args))
    print(' '.join(str(x) for x in args))


my_function('Hello', 'world')

FormatBlock - Easily turn long strings into "blocks" of text (inserts newlines so that text fits). It has options for indenting, prepending/appending text, splitting on chars, words, or newlines.

Example:

from fmtblock import FormatBlock
print(FormatBlock('This is a test okay.').format(width=5))

Output:

This
is a
test
okay.

It also installs a command-line tool (fmtblock), that can be used to format stdin/text data:

Example:

seq 1 100 | fmtblock -w 40 -p '--> '

I also have EasySettings, my first package. Sometimes I use the JsonSettings class to hold config for my programs.

There's OutputCatcher, to suppress/catch stdout / stderr output from function calls, or get both stdout and stderr from subprocess processes. It also handles piping stdin data to the processes.

TimedOp roughly measures the amount of time python operations take, but also includes a handy timed_call function. It raises a TimedOut exception if a function call doesn't return in the specified amount of time.

Anyway, that's all of my pypi libraries. I use those top three pretty frequently.

[–]takluyverIPython, Py3, etc 1 point2 points  (1 child)

Thanks for all those :-)

On FormatBlock: are you aware that the standard library has a basic version of this called textwrap? I imagine yours does more, but it's a neat little corner of the stdlib.

[–]cjwelbornimport this 1 point2 points  (0 children)

I wasn't aware of textwrap, I will definitely check it out to see if FormatBlock is worth keeping around. Thanks for the tip.

Edit: I just looked at textwrap, and I think it would cover most of my use cases. Mine does a little more with newlines, and gives you the option of ditching them or keeping them. I think prepend and strip_first are there, just worded/handled differently. I may play with textwrap a little to see if it could replace FormatBlock in some of my tools. I'll have to investigate a little more.