Questions tagged «setattr»

4
如何在当前模块上调用setattr()?
如何将第一个参数“ object”传递给函数setattr(object, name, value),以在当前模块上设置变量? 例如: setattr(object, "SOME_CONSTANT", 42); 具有与以下相同的效果: SOME_CONSTANT = 42 在包含这些行的模块中(带有正确的object)。 我在模块级别动态生成几个值,由于无法__getattr__在模块级别定义,所以这是我的后备。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.