import threading
t1 = threading.Thread(target=post_from_keyboard)
t1.start()
t1.join()
# Loop exits when users writes quit.
# Obviously it won't post any Tweets with the word "quit"
def post_from_keyboard():
while(True):
kb_tweet = input("Enter Tweet or write "quit" to exit")
if kb_tweet != "quit"
your_tweet_api_call( kb_tweet )
else:
break
也许,你在找这样的东西
我知道您不希望循环等待您在每次迭代中输入tweet,因此不能使用最常用的方法raw\u input。你知道吗
在这种情况下,它是特定于平台的。对于Unix系统,您应该使用select模块,而在Windows中,您应该使用msvcrt模块。你知道吗
使用select,我们的想法是在每次迭代中检查stdin,并在得到一个stdin时处理消息。你知道吗
比如:
我会为它创建一个特定的线程,当使用它时,我会调用你的twitterapi post函数。(但这取决于代码的结构)
相关问题 更多 >
编程相关推荐