代码:
def more (text,numlines=15):
lines = text.splitline()
while lines:
chunk = lines[:numlines]
lines = lines[numlines:]
for line in chuck: print(line)
if lines and input ('more?') not in ['y','Y']:break
if __name__ == '__main__':
import sys
more(open(sys.argv[1]).read(),10)
运行结果如下:
D:\Python Project>python more.py "new 1.txt"
Traceback (most recent call last):
File "more.py", line 10, in <module>
more(open(sys.argv[1]).read(),10)
File "more.py", line 2, in more
lines = text.splitline()
AttributeError: 'str' object has no attribute 'splitline'
尚方宝剑之说
互换的青春
相关分类