Skip to content Skip to sidebar Skip to footer

Python: Accept User Input At Any Time

I am creating a unit that will do a number of things, one of them counting cycles of a machine. While I will be transferring this over to ladder logic (CoDeSys), I am putting my i

Solution 1:

If you only want to signal a reset of the counter, you can catch KeyboardInterrupt exception.

while True:
    counter = 0
    try:
        while True:
            counter += 1
            print("counter")
    except KeyboardInterrupt:
        pass

Post a Comment for "Python: Accept User Input At Any Time"