[Python-Dev] nested scopes confusion (original) (raw)
Guido van Rossum guido@python.org
Tue, 04 Dec 2001 14:59:39 -0500
- Previous message: [Python-Dev] nested scopes confusion
- Next message: [Python-Dev] nested scopes confusion
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Answering my own question (sorry), this works:
def functions(): result = [] for i in range(10): def makefunction(index): def mth(): return index return mth mth = makefunction(i) result.append(mth) i = 25 return result for mth in functions(): print mth() But how will I understand this 3 months from now?
What's the problem with understanding this code? It looks totally clear to me. You could add a few comments or use more fancyful function names.
--Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] nested scopes confusion
- Next message: [Python-Dev] nested scopes confusion
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]