Incrementing a counter in try/except while loop

Issue

This Content is from Stack Overflow. Question asked by SomaJuice

I cannot understand why second is not incrementing in the example.
I have been looking at How would I stop a while loop after n amount of time?
And i could use the time library and a timeout to solve this, but want to do it simply by incrementing a counter, why is not possible?

import time
snipe_amount = None
second = 0
while snipe_amount is None and second < 20:
    try:
        snipe_amount = someFunctions(sds)

    except Exception as e:
        print(e)
        second =+1
        print(f"error {second}sec")
        time.sleep(1)



Solution

Check the Answers

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?