python - __getattr__ 的奇怪问题,其中项目字符串在调用期间被更改
问题描述
出于某种奇怪的原因,对于特定字符,它似乎__getattr__
以不可预知的方式改变了项目的价值。
这是一个完整的可运行示例:
class blah(object):
def __getitem__(self,item):
print(item)
print(list([ord(s) for s in item]))
def __getattr__(self, item):
print(item)
print(list([ord(s) for s in item]))
b=blah()
print("Index...")
b['ϕ']
print("__getattr__...")
b.ϕ
print("getattr()...")
getattr(b,'ϕ')
哪个输出:
Index...
ϕ
[981]
__getattr__...
φ
[966]
getattr()...
ϕ
[981]
(注意角色在__getattr__
通话中发生了变化,而不是在其他人中)。例如,并非所有角色都会发生这种情况
print("Index...")
b['θ']
print("__getattr__...")
b.θ
print("getattr()...")
getattr(b,'θ')
产量
Index...
θ
[952]
__getattr__...
θ
[952]
getattr()...
θ
[952]
想法?
解决方案
推荐阅读
- c++ - 我的搜索功能 C++ 有问题
- javascript - 将我获取的数据传递给我的插入函数
- wordpress - 无法在 WordPress 中安装插件或更新
- linux - 在linux中水平排序
- android - 在系统凭据存储android中安装证书
- cmake - clang-tidy 找不到#include
- python - 在 pandas 中为 groupby 设置一些规则
- apache-kafka - Kafka Streams 库是否会杀死空闲的 StreamThreads?
- angular - 如何在另一个模块中包含组件
- systemc - 如何在 SystemC 中使用 next_trigger() 模拟输出延迟?