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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'syntax': 0.03; 'subject:Python': 0.05; 'say,': 0.05; '21,': 0.07; 'c++,': 0.07; 'level,': 0.07; 'skip:% 20': 0.07; 'way:': 0.09; '"%"': 0.16; 'blessing': 0.16; 'lisp': 0.16; 'relevance': 0.16; 'syntax.': 0.16; 'wed,': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'mostly': 0.20; 'sort': 0.21; 'trying': 0.21; 'import': 0.21; 'java': 0.21; 'example': 0.23; '15,': 0.23; 'flexibility': 0.23; 'header:In- Reply-To:1': 0.25; 'mix': 0.27; 'message-id:@mail.gmail.com': 0.27; 'strings,': 0.29; 'up.': 0.31; 'system,': 0.32; 'skip:s 30': 0.33; 'to:addr:python-list': 0.33; 'skip:d 20': 0.34; "can't": 0.34; 'received:google.com': 0.34; 'nov': 0.35; 'pm,': 0.35; 'similar': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'really': 0.36; 'but': 0.36; '12,': 0.36; 'depends': 0.36; 'others.': 0.36; 'should': 0.36; 'two': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'easier': 0.38; 'things': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'think': 0.40; 'easy': 0.60; 'most': 0.61; 'more': 0.63; 'natural': 0.65; 'manages': 0.84; 'to:name:python': 0.84; 'unholy': 0.84; 'obvious,': 0.91 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 :content-type; bh=Q5Am7GcqcIF7vxUvVu1/NGX2moRe007dPab6H2VYwYo=; b=w3/xqKRajI0/cQrTTCWOq5Fy2mVNuk9YXS0XOHLhIsIAF1aDvljtxWuDNsl3b8NgH/ 7wu2hH4kKxlmbqmvmQPTREPcDMMiQ08Rsg/ytrzSRTfP4czxdec+/oMzzQUfWK4SvuMF /3JevfaHOlQYkGAbeehl/FeyRNyGJKatCJrM3IppCmBYqzULYilsSVgK9bit2YgNCDzE /NZBjnDLRk/TVGRhMO7BMBmrMV6tWtDb+7ufaVsnNZ+P/nuxKLN6LNNd88HFELXxk9yV gSoBZ/EDm2dvs99UyvYepWBbe2MP8eTB12pEIL4gdJemejSIjQQusbpXbMwXeOKebWpZ VTcw== MIME-Version: 1.0 In-Reply-To: References: <31a82817-8c9b-4dd2-a468-89d8d081fd1b@googlegroups.com> <50AD0962.5080002@ncf.ca> From: Ian Kelly Date: Wed, 21 Nov 2012 17:19:18 -0700 Subject: Re: Yet another Python textbook To: Python 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: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1353543590 news.xs4all.nl 6954 [2001:888:2000:d::a6]:47836 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33780 On Wed, Nov 21, 2012 at 4:21 PM, Joshua Landau wrote: > "{}".format() is a blessing an "" % () should go. "%" has no relevance to > strings, is hard to "get" and has an appalling* syntax. Having two syntaxes > just makes things less obvious, and the right choice rarer. > > str.format is also really easy. I don't understand what makes you disagree. I think it mostly depends on where you come from as a programmer. As you say, having two syntaxes muddles things up. If you come from C or C++, then the %s syntax feels natural and intuitive, and trying to learn the sort-of-similar-but-not-really {} syntax on top of it is just confusing. Conversely, if you come from Java or C#, then the {} syntax comes naturally, and having to learn %s in addition will give one a headache. And then there are those who come from Lisp and want to know why they can't just use the familiarly easy ~a syntax. None of these are really any easier than the others. But they are sort of similar at a superficial level, which just makes it that much more painful to learn one when you're already accustomed to another. I think my favorite example from the str.format documentation is this one. Apart from demonstrating the flexibility of the format system, it also manages to mix the two systems in a most unholy way: >>> import datetime >>> d = datetime.datetime(2010, 7, 4, 12, 15, 58) >>> '{:%Y-%m-%d %H:%M:%S}'.format(d) '2010-07-04 12:15:58'