淫秽的弦乐一代班轮
mapjoin的Python项目详细描述
mapjoin函数的目的是有一个替代str.join的方法 看起来更像os.path.join(使用*args)。
mapjoin()
frommapjoinimportmapjoin,strjoinmapjoin('foo',2)# raise TypeErrormapjoin('foo',2,sep='_',key=str)# return 'foo_2'# you can also make mapjoin use your own callback with the key kwarg:your_formatter=lambdakey:str(key)ifkeyelse'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()takesexactlyoneargument(2given)# and instead of "just fixit and move on", i decided try to make a joint
但也因为当代码看起来像:
readable=' '.join(map(str,['hello',f'__{name}__',something,]))# or:deffoo():readable=textwrap.dedent(f''' hello __{name}__ ''').strip()