A function for binding strings with a separator

pip install bind==2.1.0


Build Status


bind is a one-line function that joins strings in a way we often need


from bind import bind
things_to_bind = ['castable', 'to', 's t r i n g.', 45, '"hi"', 0.25]

# defaults for urllib.parse.quote_plus, leaving these out would change nothing
kwargs = dict(safe='', encoding=None, errors=None) 

# by default, use slash separator and urlencoding
bind(*things_to_bind, **kwargs)

# turn off url encoding
bind(*things_to_bind, url=False, **kwargs)
'castable/to/s t r i n g./45/"hi"/0.25'

# result is the same if you pass in a list
bind(things_to_bind, url=False, **kwargs)
'castable/to/s t r i n g./45/"hi"/0.25'

# change separator --- note that it strips the other . in things_to_bind[2]
bind(*things_to_bind, sep='.')

# pointless but possible, and will strip W, H and Y from items in iterable!
bind(*things_to_bind, sep='WHY', url=True, **kwargs)

Aside from url=bool and sep=str, all keyword arguments are passed to urllib.parse.quote_plus

Tests (600% coverage)

coverage run --source='.' -m unittest discover
coverage report
Name                Stmts   Miss  Cover
bind/        1      0   100%
bind/            2      0   100%
tests/       0      0   100%
tests/         22      0   100%
TOTAL                  25      0   100%