上下文: 我想用另一个对象替换一个对象:
x = []
r = [2]
replace(x, r)
assert x == [2]
assert x is r
在 Smalltalk 中,这将被称为 become 。
问题: 我该怎么做?我需要创建 C 扩展还是已经有类似的东西?
我试过了: This但是我需要处理很多情况。对我来说,只需更改指针后面的对象就足够了。
原因:我想实现功能、改进和主题等扩展。有时我无法更改内置对象的类 os.__class__ = X 以实现更大的灵 active 。由于我做不到,所以我考虑更换。
具体用法示例:
主观看法:
import pylung
pylung.deutsch()
import os # I want to preserve object identity with the original os
os.ERREICHE_SETZEN
os.durchlaufe(...)
翻译:
import os
import pylung
os = pylung.translate(os, 'deutsch') # German
@os.walk
def durchlaufe(ordner, oben_nach_unten, folge_links):
"""Ordner baum erzeuger
"""
请您参考如下方法:
一个简单的 = 做你想做的事:
x = []
r = [2]
x = r
assert x == [2]
assert x == r
assert x is r
