淫秽的弦乐一代班轮

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()

Participate to the story

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
virtualbox无法从java移动共享文件夹中的文件   java如何连接Android 4.3.5(GA)的apache HttpClient库?   片段中的java Recyclerview未立即显示警报对话框结果   javac(n,r)计算器程序不工作   java使用BooleanQuery还是编写更多索引?   如何在java中设置y/n循环?   java不兼容的通用通配符捕获   java如何在安卓xml中编写数据绑定时的三元操作条件   java如何使用FileDialog?   java如何创建单元测试来检测是否有人使用错误的编码编辑了文件?   java如何从唯一的字符串生成唯一的int?   java gradletomcatplugin:log4j:WARN找不到记录器的附加程序   java我的动态编程解决方案(Kefa和第一步)在codeforces中有什么问题?   java每天更新两个数据库,使它们都包含相同的有效数据集   java如何检查给定的时间是否在时间限制之间   java在单个json POST上保存父级和子级   java如何获取Solr字段类型