duangsues.is_a? SaltedFish
60 subscribers
609 photos
6 videos
91 files
562 links
🌶🐔🐟 duangsuse 的日常
尤其喜欢发些奇奇怪怪的东西
和转载别人的东西
Download Telegram
Forwarded from dnaugsuz
面向对象主要就是架构器、属性、方法仨嘛…… 对于 Python 没有抽象、多态,剩下封装、继承了。
Forwarded from dnaugsuz
好啊,那就叫构造器
Forwarded from Tt Tt
请教pathlib如何glob两种文件?
Forwarded from Tt Tt
pattern参数好像不支持正则
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 Pandaaaa Yip
你。。。被人说不会py~是有道理的。。。。
Forwarded from dnaugsuz
def merge_glob(self: Path, *patterns):
return chain(map(self.glob, patterns))
Forwarded from dnaugsuz
为什么? 🌚
Forwarded from dnaugsuz
为什么? 🌚
或许我的确是不会 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 LightQuantum
嘛 我的意思是第四行
Forwarded from dnaugsuz
Complex is better than complicated.
是啊,可是 self 哪里比 implicit this (实际上有点像作用域策略) 更 *不* complicated 的了?
Forwarded from LightQuantum
可是你这 self 是哪来的呢 是谁传进来的呢
Forwarded from dnaugsuz
况且红姐用的实现语言就是 Python,能不能别还没确定就开批了……
Forwarded from LightQuantum
建议参考了解 bound method 和 function 的区别
Forwarded from dnaugsuz
implicit 出的啊 面向对象固有的啊,constructor call 的 "fruit"
Forwarded from 任桑 今天开始做魔王
可是你还是复制粘贴来的代码啊
Forwarded from dnaugsuz
以前 C 的时候人们就喜欢用 SomeClass_someMethod(struct SomeClass*, int arg1) 这种方式来实现“面向对象”
Forwarded from dnaugsuz
好好好,我服了,我是复制粘贴的丧门犬 😩