strange behaivor of nested function

Discussion in 'Python' started by 1989lzhh, Jun 7, 2014.

  1. 1989lzhh

    1989lzhh Guest

    here is code

    def make():
    def jit(sig):
    def wrap(function):
    sig=sig[0] # unbound local error, if change to sig='' would be just fine
    return function
    return wrap
    return jit
    def f():

    It is strange that the interpreter complain about unbound local error.
    please give me some suggestion, thanks!
    Ps: I am using python 2.7
    Liu Zhenhai

    ·¢×ÔÎÒµÄ iPhone
    1989lzhh, Jun 7, 2014
    1. Advertisements

  2. You are saying:

    "sig is a local variable. Assign sig to the value of sig[0]."

    But what is sig? You've said it is a local variable, and at this point it
    doesn't have a value yet.

    Lua allows you to do this:

    sig = sig[0]

    will look up a global sig and assign it to the local sig first, but that
    can be confusing and Python doesn't do that.
    Steven D'Aprano, Jun 7, 2014
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.