Re: annonymous functions -- how to

2005-05-06 Thread Dave Benjamin
Peter Hansen wrote: > 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 dood

Re: annonymous functions -- how to

2005-05-06 Thread Peter Hansen
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...' >

Re: annonymous functions -- how to

2005-05-06 Thread Dave Benjamin
Fredrik Lundh wrote: > Dave Benjamin wrote: > >>>so name them all "func" or "next" or something, so you don't have >>>to think. once the object is bound, the name is irrlevant. >> >>Sure, you could do this, but then you'd have multiple functions at >>different nesting levels with the same name, w

Re: annonymous functions -- how to

2005-05-06 Thread Fredrik Lundh
Dave Benjamin wrote: > > so name them all "func" or "next" or something, so you don't have > > to think. once the object is bound, the name is irrlevant. > > Sure, you could do this, but then you'd have multiple functions at > different nesting levels with the same name, which would be confusing.

Re: annonymous functions -- how to

2005-05-06 Thread Dave Benjamin
Fredrik Lundh wrote: > Dave Benjamin wrote: > >>In this case, having to name these callback functions is tiring and >>awkward, and (IMHO) disrupts the flow of my function: > > so name them all "func" or "next" or something, so you don't have > to think. once the object is bound, the name is irrl

Re: annonymous functions -- how to

2005-05-06 Thread Scott David Daniels
Fredrik Lundh wrote: > > so name them all "func" or "next" or something, so you don't have > to think. once the object is bound, the name is irrlevant. > Or, you could tell him about the reserved word anonymous which can be used to created unnamed functions of values. A sample definition and use

Re: annonymous functions -- how to

2005-05-06 Thread Fredrik Lundh
Dave Benjamin wrote: > In this case, having to name these callback functions is tiring and > awkward, and (IMHO) disrupts the flow of my function: so name them all "func" or "next" or something, so you don't have to think. once the object is bound, the name is irrlevant. > def add_thingy(): >

Re: annonymous functions -- how to

2005-05-05 Thread Bengt Richter
On Thu, 05 May 2005 07:45:33 -0400, Peter Hansen <[EMAIL PROTECTED]> wrote: >Jason Mobarak wrote: >> What's wrong with: >> >> def blah(): >> def _ (a, b, c): >> a = a + 2 >> print "stmt 2" >> return a+b/c >> return doSomethingWith(_) >> >> It's basically "anonymous", it just uses

Re: annonymous functions -- how to

2005-05-05 Thread Dave Benjamin
Peter Hansen wrote: > I doubt there's a valid usecase for a "anonymous" function that has more > than a line or two. Personally, I don't think there's a good usecase > for an anonymous function longer than one line... The case that I keep running into regards event-driven programming. I need t

Re: annonymous functions -- how to

2005-05-05 Thread D H
Peter Hansen wrote: > Jason Mobarak wrote: > >> What's wrong with: >> >> def blah(): >> def _ (a, b, c): >> a = a + 2 >> print "stmt 2" >> return a+b/c >> return doSomethingWith(_) >> >> It's basically "anonymous", it just uses a name that you don't care >> about. AFAIK, it can be

Re: annonymous functions -- how to

2005-05-05 Thread Peter Hansen
Jason Mobarak wrote: > What's wrong with: > > def blah(): > def _ (a, b, c): > a = a + 2 > print "stmt 2" > return a+b/c > return doSomethingWith(_) > > It's basically "anonymous", it just uses a name that you don't care > about. AFAIK, it can be immediately clobbered later if nee

Re: annonymous functions -- how to

2005-05-04 Thread Jason Mobarak
What's wrong with: def blah(): def _ (a, b, c): a = a + 2 print "stmt 2" return a+b/c return doSomethingWith(_) It's basically "anonymous", it just uses a name that you don't care about. AFAIK, it can be immediately clobbered later if need be. Otherwise, the function shouldn't be

Re: annonymous functions -- how to

2005-05-04 Thread Bengt Richter
On Wed, 04 May 2005 23:08:16 +0200, Peter Otten <[EMAIL PROTECTED]> wrote: >Mayer wrote: > >> I would like to define a very large annonymous function, one with >> several statements in sequence. I know how to define annonymous >> functions, but I don't know how to define a sequence of statements i

Re: annonymous functions -- how to

2005-05-04 Thread Peter Otten
Mayer wrote: > I would like to define a very large annonymous function, one with > several statements in sequence. I know how to define annonymous > functions, but I don't know how to define a sequence of statements in > their body. Can this be done in Python? If so, how? No, it can't. Why do you

annonymous functions -- how to

2005-05-04 Thread Mayer
Hello: I would like to define a very large annonymous function, one with several statements in sequence. I know how to define annonymous functions, but I don't know how to define a sequence of statements in their body. Can this be done in Python? If so, how? Thanks, Mayer -- http://mail.python