Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!newspeer1.nac.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; "'',": 0.07; 'assign': 0.07; '__name__': 0.09; "ain't": 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; '~ethan~': 0.09; 'def': 0.12; 'jan': 0.12; 'dictionary,': 0.16; 'filename:fname piece:signature': 0.16; 'func': 0.16; 'lambda': 0.16; 'skip:@ 20': 0.16; 'subject:def': 0.16; 'wrote:': 0.18; 'header:User-Agent:1': 0.23; 'helpful': 0.24; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'am,': 0.29; 'statement': 0.30; '25,': 0.31; 'encouraged': 0.31; 'class': 0.32; 'becomes': 0.33; 'skip:_ 10': 0.34; 'charset:us-ascii': 0.36; 'being': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:173': 0.61; "you're": 0.61; 'name': 0.63; 'air': 0.66; '2015': 0.84; 'ethan': 0.84; 'furman': 0.84; 'subject:Alternative': 0.84; 'items,': 0.91 Date: Sat, 24 Jan 2015 17:58:55 -0800 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Alternative to multi-line lambdas: Assign-anywhere def statements References: <54C3EAD1.2010501@stoneleaf.us> In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="vjXTc5hIk1xMBIGuNLFhLN5mOdDKU61iL" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 62 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1422151185 news.xs4all.nl 2934 [2001:888:2000:d::a6]:49447 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:84538 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --vjXTc5hIk1xMBIGuNLFhLN5mOdDKU61iL Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable On 01/24/2015 11:55 AM, Chris Angelico wrote: > On Sun, Jan 25, 2015 at 5:56 AM, Ethan Furman wrot= e: >> If the non-generic is what you're concerned about: >> >> # not tested >> dispatch_table_a =3D {} >> dispatch_table_b =3D {} >> dispatch_table_c =3D {} >> >> class dispatch: >> def __init__(self, dispatch_table): >> self.dispatch =3D dispatch_table >> def __call__(self, func): >> self.dispatch[func.__name__] =3D func >> return func >> >> @dispatch(dispatch_table_a) >> def foo(...): >> pass >=20 > That's still only able to assign to a key of a dictionary, using the > function name.=20 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 '', which just ai= n't helpful when the smelly becomes air borne! ;) -- ~Ethan~ --vjXTc5hIk1xMBIGuNLFhLN5mOdDKU61iL Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQIcBAEBAgAGBQJUxE3vAAoJENZ7D1rrH75NiDEP/RE9uGKD13ytS3+sbvixGp0p 7Y0QiXvQjHtE/4K09AuuZmMWqyQ3h8Ra20Obk+ppib7cv7B3H+oB9hJoCBYJrPKL nWf+mARPP7hWjYkq1Hywrq/TdP6BSG0241peLjNhiauzApmGKbf4grI0lPwTejYg XXkJKJIqVQNeNii9GhrcGpFklbmZ/PC/K8o7Rugxai7CR3doECIBtpDjVqO0cl3h 3QIMow9yXlYYEXIQRxcM/Ozi2hYSIrNh1w3YHn7F6ni8yPYB16fQrpm0PMTmuXae lUU2t7SzjPMOlEoPZKUQy0bYpvTUjqaiy9QA7spQLlldQVf4eDjMeGK0+JC6mQql 96RvJ1bOhFnROenAQ10shRvFxVRskOiMwlwFEG6qln+nmbyLCBd1F7P9GIlHwGq+ xbK72hmHMShmAU04E8eXulFJuGXZJXw8HgG2yM2zrdQ0bmjK3YyrEE9Rnb4q/dAl XqLUht5gSjn0r2wXLnC96MkLOv0Pl6BIUO+5D4Kn5d0gNHjw/2Q/rW5Q7RCxpdQz h2/luv74IrNCFxuJOw85ex1KaKHWKN/EBcV9s91m404Z05ZI+u5h3gMDy42EKITi j+8+EAtDKaVhr4CSmkSXMgmaVriJUulkourDwtmvoTaM9cLqfL5y4uxalnOLzFE3 PPHSRlQjTjGtHOYhU27t =zl/d -----END PGP SIGNATURE----- --vjXTc5hIk1xMBIGuNLFhLN5mOdDKU61iL--