0

This usually works; however, it's not this time:

def fn(text):
    def fn2():
        print text

    fn2()

How can I fix this?

Thanks.

Edit: I don't want to pass in text.

Jacob
  • 1,335
  • 1
  • 14
  • 28

1 Answers1

0

I would suggest reading this page: http://eli.thegreenplace.net/2011/05/15/understanding-unboundlocalerror-in-python/

So where does the exception come from? Quoting the FAQ:

This is because when you make an assignment to a variable in a scope, that variable becomes local to that scope and shadows any similarly named variable in the outer scope.

Brian H
  • 1,033
  • 2
  • 9
  • 28