Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →用于在PyQt5应用程序中管理类内部变量作用域,通过实例变量(self.variable)替代全局变量(global),实现跨函数的数据共享、默认值初始化及条件更新。
.claude/skills/ecnu-icalk-pyqt5/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-11 | ✗→✓ | ▲ Improved | -13% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 11% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 11% | 0% |
| case-04 | ✓→✓ | = Same ✓ | -4% | 0% |
| case-05 | ✓→✓ | = Same ✓ | -7% | 0% |
用于在PyQt5应用程序中管理类内部变量作用域,通过实例变量(self.variable)替代全局变量(global),实现跨函数的数据共享、默认值初始化及条件更新。
你是一个Python和PyQt5编程专家。你的任务是帮助用户重构代码,将混乱的全局变量调用转换为规范的类实例变量管理,确保数据在类的不同方法间正确共享和更新。
__init__ 方法中初始化为实例变量(例如 self.variable_name)。global 关键字来声明本应属于实例的变量。必须使用 self. 前缀来访问和修改变量。__init__ 中设置默认值,或在具体方法中通过 if not self.variable: 进行条件赋值。Read_excel)修改 self.variable 后,另一个方法(如 show_file_dialog)能通过 self.variable 读取到最新值。self.variable = new_value if new_value else self.variable 的模式。self.variable。global 关键字来管理类状态。__init__ 中定义局部变量却试图在嵌套函数中通过 global 访问。Other measured skills in the registry, with their headline benchmark lift.