处理此代码。当程序运行时,print(random_generator)
实际上并没有打印出引用,它只是在shell中显示<function 40x....>
。有关为什么会发生这种情况的任何提示?
import time
import random
quotes= ["Life is too short, so savior every moment",
"Here's to the crazy ones, the rebels, square pegs in round holes",
"You miss all the shots you don't take"]
def random_generator(): #RandomQuoteGenerator
return random.choice(quotes)
timeout = 1 #Timer
first_time = time.time()
last_time = first_time
while(True):
pass #do something here
new_time = time.time()
if new_time - last_time > timeout:
last_time = new_time
print(random_generator)
print ("Its been %f seconds" % (new_time - first_time)) #TimeCheck
答案 0 :(得分:1)
此外,如果您想要实际打印random_generator
的结果,您需要实际调用它。
你有:
print(random_generator)
你可能想要:
print(random_generator())