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 | 15121 reads
|
Browse archives
Active forum topics |
Recent comments
13 weeks 2 days ago
13 weeks 3 days ago
13 weeks 3 days ago
35 weeks 4 days ago
39 weeks 6 days ago
41 weeks 3 days ago
41 weeks 3 days ago
44 weeks 1 day ago
48 weeks 5 days ago
48 weeks 5 days ago