Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'behavior,': 0.07; 'constructor': 0.07; 'python': 0.08; 'dict': 0.09; 'wed,': 0.12; 'am,': 0.13; 'wrote:': 0.15; "'w')": 0.16; '-tkc': 0.16; '[*]': 0.16; 'constructor.': 0.16; 'fname': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'line.strip()': 0.16; 'message- id:@tim.thechases.com': 0.16; 'okay,': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'side-effects': 0.16; 'subject: \n ': 0.16; 'cc:addr:python-list': 0.16; '(perhaps': 0.19; 'aug': 0.19; 'once,': 0.19; 'cc:2**0': 0.21; "aren't": 0.22; 'cc:no real name:2**0': 0.22; 'header:In- Reply-To:1': 0.22; 'code': 0.24; 'performing': 0.26; 'load': 0.26; 'correct': 0.29; 'fix': 0.29; 'cc:addr:python.org': 0.30; 'times.': 0.30; 'class': 0.31; 'subject:?': 0.31; "skip:' 10": 0.32; 'expression': 0.32; 'header:User-Agent:1': 0.34; 'e.g.': 0.34; "isn't": 0.35; 'supposed': 0.35; 'doing': 0.37; 'subject:: ': 0.38; 'somewhat': 0.38; 'steven': 0.38; 'something': 0.38; 'think': 0.38; 'should': 0.39; 'data': 0.39; 'files,': 0.39; 'your': 0.60; 'subject:one': 0.77; '03:36': 0.84; 'adjustments,': 0.84; 'subject:value': 0.84 Date: Wed, 03 Aug 2011 06:25:34 -0500 From: Tim Chase User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110616 Thunderbird/3.1.11 MIME-Version: 1.0 To: Katriel Cohn-Gordon Subject: Re: Syntactic sugar for assignment statements: one value to multiple targets? References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <4e39060f$0$29988$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Source: X-Source-Args: X-Source-Dir: Cc: python-list@python.org 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: 53 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1312370748 news.xs4all.nl 23896 [2001:888:2000:d::a6]:48752 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:10801 On 08/03/2011 03:36 AM, Katriel Cohn-Gordon wrote: > On Wed, Aug 3, 2011 at 9:25 AM, Steven D'Aprano wrote: >> a, b, c, d, e = [dict() for i in range(5)] > > I think this is good code -- if you want five different dicts, > then you should call dict five times. Otherwise Python will > magically call your expression more than once, which isn't > very nice. And what if your datatype constructor has > side-effects? If the side-effects are correct behavior (perhaps opening files, network connections, or even updating a class variable) then constructor side-effects are just doing what they're supposed to. E.g. something I use somewhat regularly in my code[*]: a,b,c,d = (file('file%i.txt', 'w') for i in range(4)) If the side-effects aren't performing the correct behavior, fix the constructor. :) -tkc [*] okay, it's more like (features, adjustments, internet, ) = (file(fname) for fname in ( 'features.txt', 'adjustments.txt', 'internet.txt' ) or even (features, adjustments, internet, ) = ( set( line.strip().upper() for line in file(fname) if line.strip() ) for fname in ( 'features.txt', 'adjustments.txt', 'internet.txt' ) to load various set() data from text-files.