Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

the OBSCENE string generation one-liner

Project description

The purpose of the mapjoin function is to have an alternative to str.join that looks more like os.path.join (which takes *args).


from mapjoin import mapjoin, strjoin

mapjoin('foo', 2)                      # raise TypeError
mapjoin('foo', 2, sep='_', key=str)    # return 'foo_2'

# you can also make mapjoin use your own callback with the key kwarg:
your_formatter = lambda key: str(key) if key else 'Nothin!'
mapjoin('foo', obj, 2, None, sep='\n', key=your_formatter)


strjoin('foo', 2)                      # 'foo-2'
strjoin('foo', 2, sep='_')             # 'foo_2'

But … why ?

Initially, because I make to many mistakes when I write an os.path.join call and then a str.join call in a row:

>>> os.path.join('a', 'b')

# and 2 seconds later i'm doing this:

>>> ' '.join('a', 'b')
TypeError: join() takes exactly one argument (2 given)

# and instead of "just fixit and move on", i decided try to make a joint

But also because I can’t get no satisfaction with my code when it looks like:

readable = ' '.join(map(str, [

# or:

def foo():
    readable = textwrap.dedent(f'''

Participate to the story

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for mapjoin, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size mapjoin-0.2.0.tar.gz (1.7 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page