1

I am turning mad with the following code :

methods = {
    'pageFunctionNewPage': myClassInstance.pageFunctionNewPage,
}
sf = 'NewPage,1,0'
functionName1 = 'PageFunction' + sf.split(',')[0]
functionName2 = 'pageFunctionNewPage'
print functionName1
print functionName2
methods[functionName1]()
methods[functionName2]()

The two prints are same on screen. The second call works well while the first one always send an error message

KeyError: 'PageFunctionNewPage'

Really cannot see what I do wrong ! Tks for pointing the mistake.

4

1 に答える 1

4
"pageFunctionNewPage" != "PageFunctionNewPage"

あなたはおそらくタイプミスをしましたfunctionName1 = 'PageFunction' + sf.split(',')[0]

于 2013-07-30T09:39:04.960 に答える