self.textboxAnswer1.resize(100,50)
self.textboxAnswer2.resize(100,50)
self.textboxAnswer3.resize(100,50)
self.textboxAnswer4.resize(100,50)
self.textboxAnswer5.resize(100,50)
self.textboxAnswer6.resize(100,50)
有没有办法把这段代码放到一个循环中,变得更有效率,似乎很重复
使用python
您可以通过getattr访问类属性:
希望这有帮助
把
textboxAnswer
放在一个循环中,然后在它上面循环:它实际上取决于对象的形式,但在这种情况下(假设我不能出于任何原因修改对象),实际上可以使用
__dict__
和正则表达式:它打印:
这是丑陋和低效,但做它的工作如果您可以更改属性在对象中的存储方式(使用列表、元组或任何其他集合),请按照这种方式操作
适用于您的情况(请记住导入
re
):相关问题 更多 >
编程相关推荐