annonymous functions -- how to
Peter Hansen
peter at engcorp.com
Fri May 6 16:31:33 EDT 2005
Dave Benjamin wrote:
> def add_thingy():
> def func(thingy_id):
> print 'got thingy id:', thingy_id
> def funnc(doodad_id):
> print 'got doodad id:', doodad_id
> def func(thingy_doodad):
> print 'thingy doodad created, froobling...'
> frooble(thingy_doodad)
> print 'froobling complete'
> with_new_thingy_doodad(thingy_id, doodad_id, func)
> with_next_doodad_id(func)
> with_next_thingy_id(func)
>
> This function now has an infinite loop. Can you spot the reason?
Not offhand, and to be completely honest, the original with the longer
names was equally unreadable. I doubt this is the best way to do
whatever the heck it is that this is supposed to do.
Oh, and while I was typing my eyes fell on "funnc" misspelled above.
Presumably that's your loop...
Spelling "func" as "_" would tend to avoid this as well, unless you have
a keyboard that repeats keys accidentally.
-Peter
More information about the Python-list
mailing list