Ich bin auf folgendes python skript gestoßen:
https://github.com/tomasbasham/ratelimi ... _init__.py
Trotz der Erklärung:
Verstehe ich nicht, warum last_called nicht einfach = 0.0 gesetzt werden kann.# To get around issues with function local scope
# and reassigning variables, we wrap the time
# within a list. When updating the value we're
# not reassigning `last_called`, which would not
# work, but instead reassigning the value at a
# particular index.
last_called = [0.0]
Kann mir das jemand auf deutsch erklären, oder Stichworte auf Deutsch nennen, die ich in einem deutschen Tutorial nachlesen kann?
Auf stackoverflow liest man als Erklärung noch:
Leider hilft das auch noch nicht um es zu verstehen.# It's a list because simple types like float are constant when captured by a closure. By making it a list, the list is constant, but its contents are not.
Wenn ich nach "function scope" suche, dann stoße ich auf Erklärungen zu lokalen und globalen Variablen. Wüsste aber nicht, warum das in diesem Fall zu einem Problem werden sollte? Liegt das an der Verwendung von decorator/wrapper? Oder den Threads?