Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'anyway.': 0.05; 'argument': 0.05; 'mrab': 0.05; 'subject:Python': 0.06; '*not*': 0.07; 'attribute': 0.07; 'explicit': 0.07; 'granted,': 0.07; 'none:': 0.07; 'odd': 0.07; 'string': 0.09; 'subject:How': 0.10; 'def': 0.12; '(note:': 0.16; 'advocating': 0.16; 'argument,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterable': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'thu,': 0.19; '>>>': 0.22; 'putting': 0.22; 'error': 0.23; 'bytes': 0.24; 'sort': 0.25; 'second': 0.26; 'pass': 0.26; 'least': 0.26; 'subject:/': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; '"",': 0.31; 'forces': 0.31; 'sep': 0.31; 'file': 0.32; 'this.': 0.32; 'stuff': 0.32; '(most': 0.33; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'skip:j 20': 0.36; 'subject:?': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'ian': 0.60; "you're": 0.61; 'first': 0.61; 'skip:n 10': 0.64; '30,': 0.65; 'default': 0.69; '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:date:message-id:subject:from:to :content-type; bh=BV++R5mI8KFzbbaBO6PFqemrPJchTa0N8fv6df8WrY0=; b=SmodOw8n/edJ47xn3gHHcX6TbUtK2Ew6J2v8AB+FKTaxp4XAWuvlZfq0dkaXVLCSL5 t5QG8I9OkWt+E1sRc/hkLy7DNYKPiRllI0j+Y+MZqK6w+OaBxhhLlA0vceN9/Qe9f9FG v7K94qiGvq/b68P3Y9yDUAloe2JBNn+fBrORh/D2UDzawg9uCLpHcCx0ypBzA2ek1Naf ceDNED2dYxbK6P/o3oo1MsO5YSBeQFakOEZNDjVgI1FEj9a8yQ5E88jxYbN8cBBmLiqD xmPZbMXw4XtMOcgGDIA5Wd563UTEVB0V/TKlb0xeLdN4c2gNxxhWo1x1NDNwpORU+7Io A6ZA== MIME-Version: 1.0 X-Received: by 10.220.109.66 with SMTP id i2mr11408720vcp.51.1370026373703; Fri, 31 May 2013 11:52:53 -0700 (PDT) In-Reply-To: References: <851ce96a-0223-42b0-8d99-902294c71f58@hc4g2000pbb.googlegroups.com> <51A7AAC0.6080509@mrabarnett.plus.com> Date: Sat, 1 Jun 2013 04:52:53 +1000 Subject: Re: How clean/elegant is Python's syntax? 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.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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1370026382 news.xs4all.nl 15991 [2001:888:2000:d::a6]:42924 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:46624 On Sat, Jun 1, 2013 at 1:43 AM, Ian Kelly wrote: > On Thu, May 30, 2013 at 1:38 PM, MRAB wrote: >> And additional argument (pun not intended) for putting sep second is >> that you can give it a default value: >> >> def join(iterable, sep=""): return sep.join(iterable) > > One argument against the default is that it is specific to the str > type. If you then tried to use join with an iterable of bytes objects > and the default sep argument, you would get a TypeError. At least not > having the default forces you to be explicit about which string type > you're joining. What about: def join(iterable, sep=None): if sep is not None: return sep.join(iterable) iterable=iter(iterable) first = next(iterable) return first + type(first)().join(iterable) Granted, it has some odd error messages if you pass it stuff that isn't strings: >>> join([[1,2,3],[4,5,6]]) Traceback (most recent call last): File "", line 1, in join([[1,2,3],[4,5,6]]) File "", line 5, in join return first + type(first)().join(iterable) AttributeError: 'list' object has no attribute 'join' but you'd get that sort of thing anyway. (NOTE: I am *not* advocating this. I just see it as a solution to one particular objection.) ChrisA