用类模拟C风格的赋值+返回值
这个方法比较好:
class DataHolder: def __init__(self, value=None): self.value = value def set(self, value): self.value = value return value def get(self): return self.value dh = DataHolder() if dh.set(something()): # do something with dh.value elif dh.set(somethingelse()): # ...
参考链接: