User loginNavigation |
A name for this form of variable capture?I have a question, which has arisen after running into an unexpected variable capture in a Python program I am working on. Here is a sample: def codeExample1(hashTable): def makeGenerator(): for keyName in hashTable: def valueGenerator(): for keyValue in hashTable[keyName]: yield keyValue yield (keyName,valueGenerator()) return makeGenerator()
Now, I was expecting What occurred instead was that To correct this unexpected behavior, one would rewrite def codeExample1(hashTable): def makeGenerator(): for keyName in hashTable: def valueGenerator(_keyName): for keyValue in hashTable[_keyName]: yield keyValue yield (keyName,valueGenerator(keyName)) return makeGenerator() So that was a bit of a long lead in, but what I'm trying to get at is what is the name for the type of variable capture exhibited by Python in this example and what is the name of the variable capture I was expecting to occur? By cjh at 2008-02-01 21:44 | LtU Forum | previous forum topic | next forum topic | other blogs | 15448 reads
|
Browse archives
Active forum topics |
Recent comments
6 days 9 hours ago
41 weeks 1 day ago
41 weeks 1 day ago
41 weeks 1 day ago
1 year 11 weeks ago
1 year 15 weeks ago
1 year 17 weeks ago
1 year 17 weeks ago
1 year 19 weeks ago
1 year 24 weeks ago