淫秽的弦乐一代班轮

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第三方库


热门话题
java如何在href中将struts2文本字段的值作为参数传递?   java检查对象属性是否为空的最佳方法是什么?   java通过Maven使用Junit类别运行Cucumber测试   java如何在selenium Webdriver(Mac)中使用Robot类上传多个文件?   如何用python绘制图形或将python转换为java和Matlab?   java Osgi捆绑包更新和ResourceBundle   java使用流api将流<@Nullable T>转换为流<@NonNull T>   java中EXCEL的平台无关连接字符串   JavaFX中的java表   java Jetty线程池和sun。HttpServer会话   JPA存储库bean的java Spring注入无法工作NullPointerException   java从另一个Kubernetes作业触发Kubernetes   我的java netbeans抽奖计划需要帮助吗   泛型中的java有界类型无法扩展另一个有界类型   如果混合使用全局构建和概要文件构建,java cxfcodegenplugin会生成错误代码   封装SQL平台之间差异的java策略?