0

I already have code for performing this task, but I can only perform this in the command prompt. The number you put into the function is words per minute, so if you input 60, you will get 60 wpm, or one word per second.

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)

I was told that I have to import curses in order to get this working in shell. How do I do that? Will I need to write something completely different?

edboysega321
  • 37
  • 1
  • 7
  • Do you want to have only one word visible at once? Or all words in a row? – sphere Dec 05 '13 at 22:13
  • Your code works perfectly for me in the python shell (running python with no arguments) and in ipython. What do you see when *you* try it? – Robᵩ Dec 05 '13 at 22:14
  • only one word visible at once. The code works in cmd – edboysega321 Dec 05 '13 at 22:14
  • By 'python shell', do you mean the Python REPL (when you run python without parameters)? IPython? IDLE? It works in REPL for me. – 9000 Dec 05 '13 at 22:14
  • " is sentence with some words this is a some. words this is a sentence with some words >>> " I am using Shell 3.3.2. IDLE specifically – edboysega321 Dec 05 '13 at 22:15
  • What is "Shell 3.2.2", where have you got it and how do you start it? If it's just Python 3.2.2, it works for me, too (in 3.2.3). I run under Linux, though. – 9000 Dec 05 '13 at 22:17
  • possible duplicate of [Implementing a backspace in Python 3.3.2 Shell using Idle](http://stackoverflow.com/questions/19187759/implementing-a-backspace-in-python-3-3-2-shell-using-idle) – Robᵩ Dec 05 '13 at 22:18
  • In any case, `curses` only work under Unix-like OSes (and OS/2), not under Windows. – 9000 Dec 05 '13 at 22:19
  • I read that page, but how can I do it in IDLE? – edboysega321 Dec 05 '13 at 22:26
  • You can't. That functionality is not available in IDLE. Neither curses, nor `'\r'`, nor ANSI escape sequences work in IDLE. – Robᵩ Dec 05 '13 at 22:29

1 Answers1

0

I"m not sure I'm clear on what the question is, but just changing your \r's to \n's and eliminating the padding may give something usable without curses:

#!/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)
dstromberg
  • 6,954
  • 1
  • 26
  • 27