9.11练习:文件访问,写一个逐页显示文本文件的程序,提示输入一个文件名,每次显示文本文件的25行,暂停并向用户提示“按任意键继续”,按键后继续执行。...

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()

  

转载于:https://www.cnblogs.com/iNeoWong/p/4754924.html

你可能感兴趣的:(python)