title: Python - using [spacebar] to pause for loop
body: <p>I am looking for a way to pause the for loop below when the user presses [spacebar] and then continue the loop from the most recent iteration when [spacebar] is pressed again. </p>
  
  <p>Currently, the script prompts the user for three values and then prints words from a text file at timed intervals until there are no words remaining.</p>
  
  <p>What would be the best way to go about this? Thanks very much.</p>
  
  <pre><code>import time
  
  with open('Textfile.txt', 'r', encoding='utf8') as file:
  
      data = file.read()
      data2 = data.split()
  
  
  def reading(start, speed, chunks):
  
      for i in range(start, len(data2), chunks):
  
          print('\r' + (' '.join(data2[i:i+chunks])), end="")
  
          time.sleep(60 / speed * chunks)
  
      print ("The End.")
  
  
  start = int(input('Where would you like to start? (word number) '))
  speed = int(input('How many words per minute? '))
  chunks = int(input('How many words at a time? '))
  
  reading(start, speed, chunks)
  </code></pre>