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 | 15335 reads
|
Browse archives
Active forum topics |
Recent comments
27 weeks 2 days ago
27 weeks 2 days ago
27 weeks 2 days ago
49 weeks 3 days ago
1 year 1 week ago
1 year 3 weeks ago
1 year 3 weeks ago
1 year 5 weeks ago
1 year 10 weeks ago
1 year 10 weeks ago