运行报错,求解决?

代码:
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'

翻阅古今
浏览 92回答 2
2回答

尚方宝剑之说

错误很明显你调用的text变量没有这个splitline函数。查阅一下对应的API看看是不是弄错了类。

互换的青春

splitlines()
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python