2012-09-26 79 views
1

我正在做一個簡單的作業遊戲。我想打印行,但讓它們打印1秒鐘。我會怎麼做呢?在不同時間有Python打印行

東西會延遲打印我猜。因此,像

"Hello" 
"My name is blahblah" 
"This is blah blah" 
"blah blah" 
"What's your name?" 
+1

的http://文檔.python.org/library/time.html#time.sleep – voscausa

回答

5

time.sleep(seconds)停頓了一秒鐘,你的情況:

import time 
strings = ["Hello","My name is blahblah","This is blah blah","blah blah","What's your name?"] 

for txt in strings: 
    print txt 
    time.sleep(1) 
+0

謝謝,我認爲這是我一直在尋找的 – user1692517

0

您可以使用time.sleep(1)給予1秒的延遲

0
import time 

while(1): 
    print("-") 
    time.sleep(1) 
0
# coding:utf-8 -*- 

import time 

def print_line(lines): 
    """ 
     print every line in lines per 1s 
    """ 
    assert type(lines) in (list, tuple, str) 
    if type(lines) == str: 
     lines = (str,) 

    for line in lines: 
     print line 
     time.sleep(1) 


if __name__ == "__main__": 
    """test print line with a simple tuple""" 

    test_data = "Hello", "My name is blahblah", "This is blah blah","blah blah","What's your name?" 
    print "print one sentence per second, begin ..." 
    print_line(test_data) 
    print "finished!"