2021年3月3日星期三

print X items from list at scheduled time intervals

I have a json array with some data (name,address), I'd like to print one name every five minutes: so far I've got this:

def get_data(i):      f = open('data.json' , 'r')      infos = json.load(f)      name = infos['people'][i]['name']      print(name)      i+=1  schedule.every(5).minutes.do(get_data, i=0)    while True:      schedule.run_pending()      time.sleep(1)  

but it obviously doesn't work because I'm setting i to zero every time that get_data gets called, is there a better way to do this?

https://stackoverflow.com/questions/66466933/print-x-items-from-list-at-scheduled-time-intervals March 04, 2021 at 08:35AM

没有评论:

发表评论