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


Groups > comp.lang.python > #84487 > unrolled thread

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

Started byChris Angelico <rosuav@gmail.com>
First post2015-01-25 06:55 +1100
Last post2015-01-25 06:55 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Alternative to multi-line lambdas: Assign-anywhere def statements Chris Angelico <rosuav@gmail.com> - 2015-01-25 06:55 +1100

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

FromChris Angelico <rosuav@gmail.com>
Date2015-01-25 06:55 +1100
SubjectRe: Alternative to multi-line lambdas: Assign-anywhere def statements
Message-ID<mailman.18094.1422129357.18130.python-list@python.org>
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. There's no way to represent fully arbitrary assignment
in Python - normally, you can assign to a name, an attribute, a
subscripted item, etc. (Augmented assignment is a different beast
altogether, and doesn't really make sense with functions.) There's no
easy way to say "@stash(dispatch_table_a['asdf'])" and have that end
up assigning to exactly that.

ChrisA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web