OBSCENE字符串生成一行代码
项目描述
mapjoin函数的目的是提供一个类似于os.path.join(它接受*args)的str.join的替代方案。
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'
但为什么?
最初,因为我连续写os.path.join调用和str.join调用时犯了很多错误
>>> 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
但也因为我不能从我的代码中获得任何满足感
readable = ' '.join(map(str, [
'hello',
f'__{name}__',
something,
]))
# or:
def foo():
readable = textwrap.dedent(f'''
hello
__{name}__
''').strip()
项目详情
关闭
mapjoin-0.2.0.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | e988d24a854fa06564ed5d14faf56f4a96d5d3eb47fab0692651e4f09381690e |
|
MD5 | 3ae5b94b54bc0e19d7851f60bbc33297 |
|
BLAKE2b-256 | fb9fd92477e4d230082bc9f57a9f17fd4fb6ed78d4b47c4b74536a1c5d4c4866 |