- 论坛徽章:
- 84
|
5可用积分
import os
import sys
def more(text, numlines=15):
lines = text.splitlines()
while lines:
chunk = lines[:numlines]
lines = lines[numlines:]
for line in chunk:
print(line)
if lines and input('More?') not in ["y", "Y"]: # <--- can not work in python2, why?
break
if __name__ == '__main__':
more(open(sys.argv[1]).read(), 10)
---------------------------------------------------------------
Traceback (most recent call last):
File "more.py", line 15, in <module>
more(open(sys.argv[1]).read(), 10)
File "more.py", line 11, in more
if lines and input('More?') not in ["y", "Y"]:
File "<string>", line 1, in <module>
NameError: name 'y' is not defined
|
最佳答案
查看完整内容
python2 input 接受的是表达式 可以输入 "Y" 带引号 或者用raw_input
|