pythonloops

Time Looping Python


How can I write code to loop in time python? I want this code loop 10 minutes in python.

msList =[]
msg = str(raw_input('Input Data :'))
msgList.append(msg)

I do not wanna use crontab because I want this code looping in my program.


Solution

  • I think you are looking for something like this:

    import time
    
    t_end = time.time() + 60 * 10
    msgList =[]
    while time.time() < t_end:
        msg = str(raw_input('Input Data :'))
        msgList.append(msg)
        print(msgList)
    

    Credit goes to this post:

    Python loop to run for certain amount of seconds