Re: c[:]()
- From: Douglas Woodrow <newsgroups@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 31 May 2007 19:40:04 +0100
On Thu, 31 May 2007 07:49:22, Warren Stringer <warren@xxxxxxxx> wrote
[...]>>def a(): return 'b'
>>def b(): print 'polly! wakey wakey'
>>c = {}
>>c['a'] = b
>>c[a()]() #works!
>
>
>(typo correction for other easily-confused newbies like myself)
>
>I think you mean
Hey Douglas,
Perhaps I was being too abstract? Here goes:
,-------------------------------
| def selector():
| ...
| return funcKey #get down get down
|
| def func():
| ...
| funcSwitch = {}
| funcSwitch[funcKey] = func
| ...
| funcSwitch[selector()]()
Thanks Warren, I was merely pointing out the typing mistake you made in your first example.
And yes, your abstract names made it difficult to guess the intention of the original code. With the meaningful names you've just provided, I can see immediately that you intended to write the 2nd working code alternative I suggested:
Oh no, I get it, you meant...
,----
| c['b'] = b
| c[a()]() #works!
`----
--
Doug Woodrow
.
- References:
- "is" and ==
- From: BlueJ774
- RE: c[:]()
- From: Warren Stringer
- Re: c[:]()
- From: Dustan
- RE: c[:]()
- From: Warren Stringer
- Re: c[:]()
- From: Douglas Woodrow
- Re: c[:]()
- From: Douglas Woodrow
- RE: c[:]()
- From: Warren Stringer
- "is" and ==
- Prev by Date: Re: strange PyLint configuration (was: PEP 8 style enforcing program)
- Next by Date: Re: Adding tuples to a dictionary
- Previous by thread: RE: c[:]()
- Next by thread: RE: c[:]()
- Index(es):
Relevant Pages
|