Forwarded from dnaugsuz
pathlib.Path.glob 🤔 那么…… 没办法就没办法,只好
from pathlib import Path
from itertools import chain
def merge_glob(self: Path, *patterns):
return chain(*[self.glob(pat) for pat in patterns]) >>>
list(merge_glob(Path("/tmp"), "*.xpi", "*.1000"))
[PosixPath('/tmp/tmp-u1g.xpi'), PosixPath('/tmp/tracker-extract-files.1000')]Forwarded from dnaugsuz
def merge_glob(self: Path, *patterns):
return chain(map(self.glob, patterns))Forwarded from dnaugsuz
为什么? 🌚
或许我的确是不会 py,但我比 py 懂得如何编程?
不过说实在话,即便我不懂 py,懂的人也没有比我常给这些并不是没意义的问题一个友好的答复
所以即便懂py的人懂了,也只是他们自己懂了,没办法教给别人,这种程度的大佬…… 很有意义?
或许我的确是不会 py,但我比 py 懂得如何编程?
不过说实在话,即便我不懂 py,懂的人也没有比我常给这些并不是没意义的问题一个友好的答复
所以即便懂py的人懂了,也只是他们自己懂了,没办法教给别人,这种程度的大佬…… 很有意义?
Forwarded from dnaugsuz
其实还可以这么写,如果不嫌没必要的话:
不过就代码复用比可读性来看,这么做意义不大
from itertools import chain
from pathlib import Path
def chain_method_result_iters(op):
def __call__(self, *args):
invoke = lambda it: op(self, it)
return chain.from_iterable( map(invoke, args) )
return __call__
merge_glob = chain_method_result_iters(Path.glob) list(merge_glob(Path("/tmp"), "*.xpi", "*.1000")) 结果同上不用高阶函数的版本不过就代码复用比可读性来看,这么做意义不大
Forwarded from dnaugsuz
看来 Python 的 core devs 还是一群文艺青年,我还以为导入这个模块可以提供
this 字面名呢Forwarded from dnaugsuz
Complex is better than complicated.
是啊,可是 self 哪里比 implicit this (实际上有点像作用域策略) 更 *不* complicated 的了?
是啊,可是 self 哪里比 implicit this (实际上有点像作用域策略) 更 *不* complicated 的了?
Forwarded from dnaugsuz
Forwarded from dnaugsuz
以前 C 的时候人们就喜欢用
SomeClass_someMethod(struct SomeClass*, int arg1) 这种方式来实现“面向对象”Forwarded from 任桑 今天开始做魔王
一会儿python不太面向对象,一会儿比python懂编程,一会儿复制粘贴一份代码过来然后说这是xx写的你也配批评?