[Python-Dev] Using and binding relative names (was Re: PEP for Better Control of Nested Lexical Scopes) (original) (raw)

Massimiliano Leoni massimiliano.leoni at katamail.com
Sun Feb 26 15:27:34 CET 2006


Why would you change the Python scoping rules, instead of using the function attributes, available from release 2.1 (PEP 232) ? For example, you may write:

def incgen(start, inc): def incrementer(): incrementer.a += incrementer.b return incrementer.a incrementer.a = start - inc incrementer.b = inc return incrementer

f = incgen(100, 2) g = incgen(200, 3) for i in range(5): print f(), g()

The result is:

100 200 102 203 104 206 106 209 108 212



More information about the Python-Dev mailing list