Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #84538

Re: Alternative to multi-line lambdas: Assign-anywhere def statements

Date 2015-01-24 17:58 -0800
From Ethan Furman <ethan@stoneleaf.us>
Subject Re: Alternative to multi-line lambdas: Assign-anywhere def statements
References <CAPTjJmrAQgtauH74dwCzb_-6T09D0dLVkxiGrAxJMp_OOwgS0g@mail.gmail.com> <54C3EAD1.2010501@stoneleaf.us> <CAPTjJmohdQbK9_ikh8heaMRbpJ270UW6C1AE2oNVgV_4AoYfQg@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.18121.1422151185.18130.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On 01/24/2015 11:55 AM, Chris Angelico wrote:
> On Sun, Jan 25, 2015 at 5:56 AM, Ethan Furman <ethan@stoneleaf.us> wrote:
>> If the non-generic is what you're concerned about:
>>
>> # not tested
>> dispatch_table_a = {}
>> dispatch_table_b = {}
>> dispatch_table_c = {}
>>
>> class dispatch:
>>   def __init__(self, dispatch_table):
>>     self.dispatch = dispatch_table
>>   def __call__(self, func):
>>     self.dispatch[func.__name__] = func
>>     return func
>>
>> @dispatch(dispatch_table_a)
>> def foo(...):
>>    pass
> 
> That's still only able to assign to a key of a dictionary, using the
> function name. 

This is a Good Thing.  The def statement populates a few items, __name__ being one of them.  One of the reasons lambda
is not encouraged is because its name is always '<lambda>', which just ain't helpful when the smelly becomes air borne!  ;)

--
~Ethan~

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Alternative to multi-line lambdas: Assign-anywhere def statements Ethan Furman <ethan@stoneleaf.us> - 2015-01-24 17:58 -0800
  Re: Alternative to multi-line lambdas: Assign-anywhere def statements Yawar Amin <yawar.amin@gmail.com> - 2015-01-24 18:30 -0800
    Re: Alternative to multi-line lambdas: Assign-anywhere def statements Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-25 15:27 +1100
      Re: Alternative to multi-line lambdas: Assign-anywhere def statements Yawar Amin <yawar.amin@gmail.com> - 2015-01-25 17:26 -0800
        Re: Alternative to multi-line lambdas: Assign-anywhere def statements Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-26 13:46 +1100
  Re: Alternative to multi-line lambdas: Assign-anywhere def statements albert@spenarnc.xs4all.nl (Albert van der Horst) - 2015-02-11 13:04 +0000
    Re: Alternative to multi-line lambdas: Assign-anywhere def statements Clarence <clarence1126@gmail.com> - 2015-02-11 06:28 -0800
    Re: Alternative to multi-line lambdas: Assign-anywhere def statements Ethan Furman <ethan@stoneleaf.us> - 2015-02-11 08:52 -0800
    Re: Alternative to multi-line lambdas: Assign-anywhere def statements Terry Reedy <tjreedy@udel.edu> - 2015-02-11 21:06 -0500
    Re: Alternative to multi-line lambdas: Assign-anywhere def statements Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-11 19:57 -0700
    Re: Alternative to multi-line lambdas: Assign-anywhere def statements Chris Angelico <rosuav@gmail.com> - 2015-02-12 14:56 +1100
    Re: Alternative to multi-line lambdas: Assign-anywhere def statements Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-12 09:17 -0700

csiph-web