我正在编写一个脚本,该脚本需要从txt文件打印第1行,休息3秒钟,打印第2行,休息3秒钟,然后继续直到以这种方式打印整个文本文件。我该如何实现?
答案 0 :(得分:0)
import time
file = open("abc.txt","r") #<-- Opening file as read mode
data = file.read() #<-- Reading data
file.close() #<-- Closing file
data = data.split("\n") #<-- Splitting by new lines
for i in data: #<-- Looping through splitted data
print(i) #<-- Printing line
time.sleep(3) #<-- Waiting for 3 seconds