class A(object): n = 25 def __init__(self, filename): self.__filename = filename self.f = open(self.__filename) def func(self): k = self.f.readline() print k, self.n -= 1 if k != '' and self.n == 0: raw_input('Press any key to continue.') self.n = 25 if k != '' and self.n > 0: self.func() else: self.f.close() a = A('/Users/wm/coding/1') a.func()