duangsues.is_a? SaltedFish
60 subscribers
609 photos
6 videos
91 files
562 links
🌶🐔🐟 duangsuse 的日常
尤其喜欢发些奇奇怪怪的东西
和转载别人的东西
Download Telegram
Forwarded from NoOne Mr.
如果是将字符串转换成数字的话,直接使用工厂函数转就行,int(), float()
Forwarded from dnaugsuz
『工厂函数』以后叫『架构器』即可
Forwarded from NoOne Mr.
哈哈哈,还是“架构器”听起来高大上😁
Forwarded from dnaugsuz
我觉得工厂函数听起来不常见呢,而且对于面向对象来说,架构器(constructor) 是术语
架构函数只能说是 Python、Ruby、Kotlin 里面用户的一种相对片面的理解
Forwarded from 𝔽𝕣𝕠𝕤𝕥
factory function
constructor已经被构造函数占用了
Forwarded from 𝔽𝕣𝕠𝕤𝕥
架构一般理解是architecture,不合适
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 是哪来的呢 是谁传进来的呢