A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2006-February/061842.html below:

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

[Python-Dev] Using and binding relative names (was Re: PEP for Better Control of Nested Lexical Scopes) [Python-Dev] Using and binding relative names (was Re: PEP for Better Control of Nested Lexical Scopes)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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4