我来自 ruby/C#,是 Python 的新手。
我正在查看以下代码:
def raiseFlag():
global flag
flag = 1
class TermStructureTest():
def testImpliedObs(self):
global flag
flag = None
h = RelinkableYieldTermStructureHandle()
settlement = self.termStructure.referenceDate()
new_settlement = self.calendar.advance(settlement,3,Years)
implied = ImpliedTermStructure(h,new_settlement)
obs = Observer(raiseFlag)
obs.registerWith(implied)
h.linkTo(self.termStructure)
if not flag:
self.fail("Observer was not notified of term structure change")
为什么在 TermStructureTest() 类中调用“raiseFlag”有效?