name 'times' is used prior to global declaration - But IT IS declared!

后端 未结 5 903
不思量自难忘°
不思量自难忘° 2020-12-05 23:11

I\'m coding a small program to time and show, in a ordered fashion, my Rubik\'s cube solvings. But Python (3) keeps bothering me about times being used prior to global decla

5条回答
  •  無奈伤痛
    2020-12-05 23:38

    The global declaration is when you declare that times is global

    def timeit():
        global times # <- global declaration
        # ...
    

    If a variable is declared global, it can't be used before the declaration.

    In this case, I don't think you need the declaration at all, because you're not assigning to times, just modifying it.

提交回复
热议问题