从for循环输出发送推文

时间:2017-02-06 10:34:56

标签: python loops tweepy

dict = {'57':{"number":"one","cost":"11"},'86':{"number":"two","cost":"55"},'12':{"number":"three","cost":"76"}}
for k,v in dict.items():
        print('id:',k + ',','num:' + v['number'],'cost:' +  v['cost'])

输出:

id: 57, num:one cost:11
id: 86, num:two cost:55
id: 12, num:three cost:76

嗨,我怎么能发送这三条输出行的推文,因为如果我使用了api.update_status()它会发送3条分开的推文

1 个答案:

答案 0 :(得分:0)

制作一个字符串并发推特一次,就像这样,

dict = {'57':{"number":"one","cost":"11"},'86':{"number":"two","cost":"55"},'12':{"number":"three","cost":"76"}}
data_to_tweet = '\n'.join(['id: '+k+',num: '+v['number']+' cost: '+v['cost'] for k,v in dict.items()])
tweet(data_to_tweet) #Tweeting happening here,