功能
實(shí)現(xiàn)像more分頁(yè)的功能
- 技巧:注意本段代碼的if那段寫法
- read方法會(huì)一次性將文件的內(nèi)容讀入內(nèi)存
def more(text, line=10):
lines = text.splitlines()
while lines:
page = lines[:line]
lines = lines[line:]
for row in page:
print(row)
if lines and input(r'More? "N" or "n" for quit!') in ('N','n'):break
if __name__ == '__main__':
import sys
text = open(sys.argv[1],encoding="utf8").read()
more(text, 15)