The purpose of the mapjoin function is to have an alternative to str.join that looks more like os.path.join (which takes *args).
mapjoin()
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()
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')
'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, [
'hello',
f'__{name}__',
something,
]))
# or:
def foo():
readable = textwrap.dedent(f'''
hello
__{name}__
''').strip()
Metadata
Release files for mapjoin 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mapjoin-0.2.0.tar.gz | 1.7 kB | Details |
Release files / mapjoin-0.2.0.tar.gz
| Download URL | mapjoin-0.2.0.tar.gz |
|---|---|
| Size | 1.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e988d24a854fa06564ed5d14faf56f4a96d5d3eb47fab0692651e4f09381690e
|
|
BLAKE2b-256 checksum How to use checksums |
fb9fd92477e4d230082bc9f57a9f17fd4fb6ed78d4b47c4b74536a1c5d4c4866
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.6
|