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


Groups > comp.lang.python > #11702

Re: Syntactic sugar for assignment statements: one value to multiple targets?

References (1 earlier) <j2eki3$43t$1@dont-email.me> <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> <mailman.117.1313565232.27778.python-list@python.org> <c6cd02ea-3020-4970-82c6-8d289738bf37@o11g2000yql.googlegroups.com> <4E4BF297.7040901@mrabarnett.plus.com>
Date 2011-08-17 18:25 +0100
Subject Re: Syntactic sugar for assignment statements: one value to multiple targets?
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.139.1313601914.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Aug 17, 2011 at 5:55 PM, MRAB <python@mrabarnett.plus.com> wrote:
> x, y, z = lazy copies(SuperComplexClass(param1, etc, ...))
>

This assumes that you can construct it once and then copy it reliably,
which may mean that the class implement copying correctly. It also
wouldn't work with:

a, b, c, d = *random.randint(1,20)

which would roll 4d20 and get the results in separate variables. The
OP's idea of separately evaluating the expression would; but to do it
with copying would require a special "randint" object that functions
exactly as an integer but, when copied, would re-randomize.

Perhaps * is the wrong syntactic element to use. Maybe it needs a
special assignment operator:

a, b, c, d @= random.randint(1,20)

which would evaluate its left operand as a tuple of lvalues, then
evaluate its right operand once for each element in the left operand,
and assign to each element in turn. (I've no idea what form of
assignment operator would be suitable, but @= is currently illegal, so
it ought to be safe at least for discussion purposes.)

Chris Angelico

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


Thread

Syntactic sugar for assignment statements: one value to multiple targets? gc <gc1223@gmail.com> - 2011-08-02 18:45 -0700
  Re: Syntactic sugar for assignment statements: one value to multiple targets? Chris Angelico <rosuav@gmail.com> - 2011-08-03 03:09 +0100
  Re: Syntactic sugar for assignment statements: one value to multiple targets? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-03 18:25 +1000
    Re: Syntactic sugar for assignment statements: one value to multiple targets? Tim Chase <python.list@tim.thechases.com> - 2011-08-03 06:15 -0500
    Re: Syntactic sugar for assignment statements: one value to multiple targets? Tim Chase <python.list@tim.thechases.com> - 2011-08-03 06:25 -0500
      Re: Syntactic sugar for assignment statements: one value to multiple targets? gc <gc1223@gmail.com> - 2011-08-16 12:50 -0700
  Re: Syntactic sugar for assignment statements: one value to multiple targets? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-08-03 20:29 +1200
  Re: Syntactic sugar for assignment statements: one value to multiple targets? "Martin P. Hellwig" <martin.hellwig@gmail.com> - 2011-08-16 21:39 +0100
    Re: Syntactic sugar for assignment statements: one value to multiple targets? gc <gc1223@gmail.com> - 2011-08-16 17:14 -0700
      Re: Syntactic sugar for assignment statements: one value to multiple targets? MRAB <python@mrabarnett.plus.com> - 2011-08-17 03:11 +0100
      Re: Syntactic sugar for assignment statements: one value to multiple targets? Chris Angelico <rosuav@gmail.com> - 2011-08-17 08:13 +0100
        Re: Syntactic sugar for assignment statements: one value to multiple targets? gc <gc1223@gmail.com> - 2011-08-17 02:26 -0700
          Re: Syntactic sugar for assignment statements: one value to multiple targets? Chris Angelico <rosuav@gmail.com> - 2011-08-17 10:45 +0100
            Re: Syntactic sugar for assignment statements: one value to multiple targets? gc <gc1223@gmail.com> - 2011-08-17 03:33 -0700
          Re: Syntactic sugar for assignment statements: one value to multiple targets? Terry Reedy <tjreedy@udel.edu> - 2011-08-17 12:12 -0400
          Re: Syntactic sugar for assignment statements: one value to multiple targets? MRAB <python@mrabarnett.plus.com> - 2011-08-17 17:55 +0100
          Re: Syntactic sugar for assignment statements: one value to multiple targets? Chris Angelico <rosuav@gmail.com> - 2011-08-17 18:25 +0100
          Re: Syntactic sugar for assignment statements: one value to multiple targets? "OKB (not okblacke)" <brenNOSPAMbarn@NObrenSPAMbarn.net> - 2011-08-17 19:13 +0000
      Re: Syntactic sugar for assignment statements: one value to multiple targets? Zero Piraeus <schesis@gmail.com> - 2011-08-17 16:07 -0400
  Re: Syntactic sugar for assignment statements: one value to multiple targets? Ethan Furman <ethan@stoneleaf.us> - 2011-08-17 12:52 -0700
  Re: Syntactic sugar for assignment statements: one value to multiple targets? John Pinner <funthyme@gmail.com> - 2011-08-18 02:26 -0700
  Re: Syntactic sugar for assignment statements: one value to multiple targets? Roy Smith <roy@panix.com> - 2011-08-18 09:13 -0400

csiph-web