python 语句的作用是什么?
What is the effect of this python statement?
我正在尝试探索 Kivy API,我对在他们 multitexture example 中发现的一些代码行感到非常困惑。一行代码似乎将值“1”分配给 "self.canvas" 中的 "texture0" 键,将 "self.canvas" 视为 python 字典。
那个密码是self.canvas['texture0'] = 1
但是,当我越过调试器的这一行时,我在 self.canvas 中看不到这样的条目,并且 self.canvas 的类型是 "RenderContext"。事实上,我没有看到任何迹象表明该语句更改了调试器中可观察到的任何内容,但如果我计算 self.canvas['texture0']
,它的计算结果为“1”。
这个值存储在哪里?我在 Kivy 的 canvas docs
中也找不到任何线索
treating "self.canvas" as though it is a python dictionary.
这与字典没有特别的关系,使用 [] 符号只是调用 __getitem__
或 __setitem__
- 参见 the Python docs。碰巧 class 在这种情况下将数据存储在内部字典中,但这是一个实现细节,不是此语法所要求的。
However, when I step past this line the debugger, I see no such entry in self.canvas
canvas对象在cython中定义,用于此存储的内部状态属性对Python代码不可见
我正在尝试探索 Kivy API,我对在他们 multitexture example 中发现的一些代码行感到非常困惑。一行代码似乎将值“1”分配给 "self.canvas" 中的 "texture0" 键,将 "self.canvas" 视为 python 字典。
那个密码是self.canvas['texture0'] = 1
但是,当我越过调试器的这一行时,我在 self.canvas 中看不到这样的条目,并且 self.canvas 的类型是 "RenderContext"。事实上,我没有看到任何迹象表明该语句更改了调试器中可观察到的任何内容,但如果我计算 self.canvas['texture0']
,它的计算结果为“1”。
这个值存储在哪里?我在 Kivy 的 canvas docs
中也找不到任何线索treating "self.canvas" as though it is a python dictionary.
这与字典没有特别的关系,使用 [] 符号只是调用 __getitem__
或 __setitem__
- 参见 the Python docs。碰巧 class 在这种情况下将数据存储在内部字典中,但这是一个实现细节,不是此语法所要求的。
However, when I step past this line the debugger, I see no such entry in self.canvas
canvas对象在cython中定义,用于此存储的内部状态属性对Python代码不可见