Path: csiph.com!usenet.pasdenom.info!news.franciliens.net!fdn.fr!usenet-fr.net!nerim.net!novso.com!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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'class,': 0.07; 'function,': 0.09; 'indeed,': 0.09; 'okay': 0.09; 'cc:addr:python- list': 0.11; 'def': 0.12; 'thread': 0.14; '23,': 0.16; '__init__,': 0.16; 'comp': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'opt):': 0.16; 'roy': 0.16; 'sane': 0.16; 'subclass': 0.16; 'threads,': 0.16; 'wrote:': 0.18; 'examples': 0.20; 'saying': 0.22; 'cc:addr:python.org': 0.22; 'all:': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'dec': 0.30; 'message-id:@mail.gmail.com': 0.30; 'bunch': 0.31; 'class': 0.32; 'sense': 0.34; 'skip:_ 10': 0.34; 'could': 0.34; 'received:google.com': 0.35; 'subject:List': 0.36; 'list': 0.37; 'starting': 0.37; 'being': 0.38; 'skip:[ 10': 0.38; 'either': 0.39; 'subject:skip:C 10': 0.61; 'simply': 0.61; 'name': 0.63; 'here': 0.66; 'side': 0.67; 'smith': 0.68; 'effects.': 0.91; 'to:none': 0.92; 'opt': 0.97 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=4FB+UFDEGDf/o8foZ12JcMSKx2JazDQbAgh2PgioX/Q=; b=x7ucq2zlbjf90X8WQzoAEwRKv7g1R4cpNpC3PTgLK/j0hqbyF/MIJpiDPvzdWMKaC6 yl55A0jlZ3pNlnTf5iIGW1ItVG6FE1Gpxu1SNGIJ1+rbJQDfs7gSSv0NDauGzbE6PeUJ cIjG3tmfo8e6cIH2j3Sq/BzFodp0E9SVF0AFEH7nQqllxw68CgIPnj5ToOVsvgeopspQ Qi56+r+1wkB/4abmn9T8lEMt47ZJSkD7BQ0in35TAbs3mMzoU0ccNUbvjbvk0u7znt+5 6M0J57p4L/8qF4fbHCAV42etXyIEp/5fVhqLwbD6DqK2WfgN2wpWYEMEptve2O700u9+ 8Drw== MIME-Version: 1.0 X-Received: by 10.107.7.94 with SMTP id 91mr19868561ioh.27.1419254482231; Mon, 22 Dec 2014 05:21:22 -0800 (PST) In-Reply-To: References: Date: Tue, 23 Dec 2014 00:21:22 +1100 Subject: Re: List Comprehensions From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1419254490 news.xs4all.nl 2886 [2001:888:2000:d::a6]:36096 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:82771 On Tue, Dec 23, 2014 at 12:07 AM, Roy Smith wrote: > def init_thread(opt): > opt['result'] = Queue.Queue() > thread = pause.Thread(opt) > thread.start() > return thread > > threads = [init_thread(opt) for opt in options] If this is, indeed, just initializing the threads, then this might make sense. Or alternatively, if you could subclass threading.Thread and do all the work in __init__, then you could simply construct them all: class whatever(thread.Thread): def __init__(self, opt): self.queue = Queue.Queue() self.opt = opt super().__init__() self.start() threads = [whatever(opt) for opt in options] Just as long as you can come up with a sane name for the class, or the initializer function, that makes sense without the list comp. Incidentally, this is part of what I was saying about side effects being okay in a list comp; either Roy's or my examples here would be a list comp that has the side effect of starting a bunch of threads, and I don't see it as being at all problematic. Just don't use a list comp for _just_ the side effects. ChrisA