#!/usr/bin/python class FooBar: def __init__(self): self.x = 1 def a(self): if self.x < 5: self.x += 1 return "hello" else: def newa(self): return "world" self.a = newa self.a(self) f = FooBar() for x in range(1,8): print(f.a())