我正在為模塊級構造創建一個進入/退出塊。我有以下示例來測試如何從類中訪問模塊級變量:_variableScope = ''class VariableScope(object): def __init__(self, scope): self._scope = scope def __enter__(self): global _variableScope _variableScope += self._scopex = VariableScope('mytest')x.__enter__()print(_variableScope)這讓我得到了 的預期值'mytest',但是......使用globalinside__enter__()方法是否正確和良好的做法?
添加回答
舉報
0/150
提交
取消