1

I have txt file with a list of words, and i want to read:

  1. Each word (from the txt file) with delay of 10 sec, and to "Do something". Then read the second word and "Do something" etc.
  2. Four words (at the same time) with the same delay.

I am using Python27.

My code is:

# Read text file
with open('D:\My_Path.txt', 'r') as fp:
lines = [line.rstrip('\n') for line in fp.readlines()]
time.sleep(10)  # does not work well
for line in lines:
    print (line)

def AB ():
    '''Do something'''
AB ()
Mypel
  • 149
  • 1
  • 1
  • 10
  • Possible duplicate of https://stackoverflow.com/questions/510348/how-can-i-make-a-time-delay-in-python – Henry Woody Oct 19 '18 at 22:43
  • You can use the `time.sleep(10)` function which puts in a delay of 10 seconds before executing the next instructions. – Karl Oct 19 '18 at 22:45
  • The common way to introduce delays in code execution is Python is by calling [`time.sleep()`](https://docs.python.org/3/library/time.html#time.sleep) – martineau Oct 19 '18 at 22:45
  • @ Karl, i did it, but still i did not read each word by word with delay. – Mypel Oct 19 '18 at 22:46

1 Answers1

2

Add import time at the beginning and e.g. time.sleep(.3) before print(line).

Felix
  • 1,837
  • 9
  • 26