0

Why does the following variable not pass to the closure:

def something():
    UPDATED = 0
    def _inner():
        UPDATED += 1

But this one does:

def something():
    UPDATED = {0:0}
    def _inner():
        UPDATED[0] += 1

I find myself using the latter approach as a sort of hack to get around referencing a global var, but why does that one work and the first doesn't?

samuelbrody1249
  • 4,379
  • 1
  • 15
  • 58

0 Answers0