We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gdict
dict
用 gdict 覆盖内嵌 dict,这样以后在全局创建例如 {'a': 'A'} 即可直接得到 gdict 实例,而无需再做转换。
{'a': 'A'}
The text was updated successfully, but these errors were encountered:
初步尝试,从 builtins 中篡改 dict。尝试未成功,如下代码:
builtins
>>> import builtins >>> import gqylpy_dict >>> builtins.dict = gqylpy_dict.gdict
此时查看 dict,出现一个奇特的现象:
>>> dict.__qualname__ 'GqylpyDict' >>> dict().__class__.__qualname__ 'dict' >>> {}.__class__.__qualname__ 'dict'
全局 dict 已经指向 gdict,但调用全局 dict 得到的却仍是内嵌 dict 的实例。这样看来,调用全局 dict 并不是调用 builtins.dict。Python是一门高深的语言,你永远也猜不到它的底层设计。
builtins.dict
Sorry, something went wrong.
尝试方案二,从 globals 中篡改 dict:
globals
>>> import gqylpy_dict >>> globals()['dict'] = gqylpy_dict.gdict
此时查看 dict:
>>> dict.__qualname__ 'GqylpyDict' >>> dict().__class__.__qualname__ 'GqylpyDict' >>> {}.__class__.__qualname__ 'dict'
看起来比上一次成功,全局 dict 已经指向 gdict,调用全局 dict 也得到 gdict 实例,但使用 {} 的方式 仍得到内嵌 dict 实例。
{}
2018-11-27
No branches or pull requests
用
gdict
覆盖内嵌dict
,这样以后在全局创建例如{'a': 'A'}
即可直接得到gdict
实例,而无需再做转换。The text was updated successfully, but these errors were encountered: