我已经有了执行此任务的代码,但我只能在命令提示符下执行此操作。你输入函数的数字是每分钟的单词,所以如果你输入60,你将获得60 wpm,或每秒一个单词。
import sys
import time
data = "is sentence with some words this is a some. words this is a sentence with some words".split()
def inputwordsperminute(x):
max_len=max([len(w) for w in data])
pad = " "*max_len
for w in data:
sys.stdout.write('%s\r' % pad)
sys.stdout.write("%s\r" % w)
sys.stdout.flush()
time.sleep((60.0/x))
print
inputwordsperminute(200)
我被告知我必须导入curses以便在shell中使用它。我怎么做?我需要写一些完全不同的东西吗?
答案 0 :(得分:0)
我不确定我清楚问题是什么,但只是将你的\ r更改为\ n并删除填充可能会在没有诅咒的情况下提供一些可用的东西:
#!/usr/local/cpython-2.7/bin/python
import sys
import time
data = "is sentence with some words this is a some. words this is a sentence with some words".split()
def inputwordsperminute(x):
#max_len=max([len(w) for w in data])
#pad = " "*max_len
for w in data:
#sys.stdout.write('%s\n' % pad)
sys.stdout.write("%s\n" % w)
sys.stdout.flush()
time.sleep((60.0/x))
print
inputwordsperminute(200)