Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder4.news.weretis.net!newsfeed.kpn.net!pfeed08.wxs.nl!newsfeed.xs4all.nl!newsfeed5.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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'assign': 0.04; 'mrab': 0.04; 'operator': 0.05; 'roll': 0.07; 'tuple': 0.09; 'variables.': 0.09; 'copied,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'illegal,': 0.16; 'syntactic': 0.16; 'wrote:': 0.16; "wouldn't": 0.17; 'wed,': 0.17; 'maybe': 0.21; 'discussion': 0.22; 'header:In-Reply-To:1': 0.22; 'assumes': 0.23; 'etc,': 0.23; 'pm,': 0.24; 'aug': 0.24; 'correctly.': 0.24; 'separate': 0.28; 'message-id:@mail.gmail.com': 0.29; 'construct': 0.30; 'operand': 0.30; 'separately': 0.30; 'class': 0.30; 'subject:?': 0.31; 'least': 0.31; 'chris': 0.32; 'expression': 0.32; 'implement': 0.32; 'to:addr:python-list': 0.33; 'copying': 0.33; 'but,': 0.34; 'idea': 0.34; '17,': 0.34; 'assignment': 0.34; 'integer': 0.34; 'object': 0.35; 'element': 0.37; 'but': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'to:addr:python.org': 0.39; 'results': 0.61; 'special': 0.67; 'safe': 0.69; 'evaluate': 0.71; 'subject:one': 0.77; "(i've": 0.84; 'subject:value': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=wOeDvXvCEU4ZMaFFAQJVq37CTPH9X34Tqp6jInAiqnE=; b=X1s1loEDR65TOEn6zjsqc3IYn1WTUtMbSEkDkDe4kp3OnfjoCZeZkLQG39ngufHNXR Lt/a+TyJrbQjj5XMxxKNwg3C8N70Fjo0uZ4uCvBcuqmVzpAt7d7AmHrS0sAyl5vtiFO/ 1k0OKGg/M8ielIIWsF8m8HML97qZ4CECOJgiE= MIME-Version: 1.0 In-Reply-To: <4E4BF297.7040901@mrabarnett.plus.com> References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> <4E4BF297.7040901@mrabarnett.plus.com> Date: Wed, 17 Aug 2011 18:25:12 +0100 Subject: Re: Syntactic sugar for assignment statements: one value to multiple targets? From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1313601914 news.xs4all.nl 23844 [2001:888:2000:d::a6]:59800 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:11702 On Wed, Aug 17, 2011 at 5:55 PM, MRAB 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