Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news2.arglkargh.de!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.038 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.01; 'else:': 0.03; 'string': 0.09; 'try:': 0.09; 'val': 0.09; 'cc:addr:python-list': 0.11; 'cc:name:python list': 0.16; 'iterables': 0.16; 'simpler,': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'raise': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'cases': 0.33; 'maybe': 0.34; 'except': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'similar': 0.36; 'solve': 0.60; 'august': 0.61; "you'll": 0.62; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'oscar': 0.84; 'subject:space': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=Fb7ouBbZwZ8o1A2VlfqSvH0gJVVhvQ8GK/+95psRfqU=; b=tZLnY+28ADzWTkMiZgJraJYS4bLPfudVmVkPvBUM/rHNxb3ZfshottKm7vvInOWPLL CCfkJREdV0ynmunvKOkhLPF1TQ6B7zhRYt23HDQUUELYOOtoseds2mVQySVT2GeMgJcL Qnk9I94Wkvpi7AhpFp0E94v/1a7PC6JjE3AQBV+rwBoHLS1TVKtZ2VFto1DwD8NWL2oF /ZngAU4QRBZHbAMOo+Wfsw2/cUBg7yuj3cC0Ozq8dDIz8Am7L8toFA82XlZB7xP8bo4q 5T5vnyR9UDCWQ2cVm0Bv/nYiP/miJN3z1PG3hWFIjl02PpoCRiM/BMX4dHxcgH7AhacM ZAjw== X-Received: by 10.52.35.171 with SMTP id i11mr10950186vdj.4.1377963859547; Sat, 31 Aug 2013 08:44:19 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <5221a693$0$2059$426a74cc@news.free.fr> <5221b68b$0$2280$426a74cc@news.free.fr> <5221f0af$0$2412$426a34cc@news.free.fr> From: Oscar Benjamin Date: Sat, 31 Aug 2013 16:43:59 +0100 Subject: Re: print function and unwanted trailing space To: Chris Angelico Content-Type: text/plain; charset=ISO-8859-1 Cc: Python List 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1377963862 news.xs4all.nl 15904 [2001:888:2000:d::a6]:39783 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:53366 On 31 August 2013 16:30, Chris Angelico wrote: >> >> but doesn't solve all the cases (imagine a string or an iterator). > > Similar but maybe simpler, and copes with more arbitrary iterables: > > it=iter(range(5)) > print(next(it), end='') > for i in it: > print('',i, end='') If you want to work with arbitrary iterables then you'll want it = iter(iterable) try: val = next(it) except StopIteration: pass # Or raise or something? else: print(val, end='') for i in it: print('', i, end='') Oscar