Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'broken': 0.04; 'subject:Python': 0.06; 'dynamically': 0.07; '"if': 0.09; '*args,': 0.09; 'arguments': 0.09; 'lawrence': 0.09; 'parsing': 0.09; 'pep': 0.09; 'def': 0.12; 'changes': 0.15; '**kwargs)': 0.16; '**kwargs):': 0.16; 'arguments;': 0.16; 'docstrings': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'work"': 0.16; '(you': 0.16; 'do,': 0.16; 'language': 0.16; 'wrote:': 0.18; 'meant': 0.20; 'print': 0.22; 'error': 0.23; 'decide': 0.24; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'raise': 0.29; 'especially': 0.30; 'message- id:@mail.gmail.com': 0.30; 'there.': 0.32; 'stuff': 0.32; 'option': 0.32; 'quite': 0.32; 'fri,': 0.33; 'there,': 0.34; 'maybe': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'being': 0.38; 'skip:o 20': 0.38; 'system,': 0.38; 'depends': 0.38; 'nov': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'that,': 0.38; 'though,': 0.39; 'to:addr:python.org': 0.39; 'changed': 0.39; 'break': 0.61; "you're": 0.61; 'kind': 0.63; 'accounts': 0.64; 'benefit': 0.68; 'advantages': 0.68; 'percent': 0.68; 'statement,': 0.68; 'acts': 0.74; 'ambiguous': 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:date:message-id:subject:from:to :content-type; bh=xKyAMDYHagSerY72JQjgshi4jnhMs+7tpuVCaW1U1+U=; b=yolvDSd3HPJlTRUH52ysYFR62fEGeDuD90dYq6RSnSPiEQMdtJ+LtXqctkVew4+d7k UB6dPSZ2Z15y3DQo2CuamGCi8AuzuvyGF9cgyV3PIblMDBgQWZ8s5D4wVPObaYcoY83h 3ub3kEcFuy3YwoxvKUimWKTK5Zp0yhJALN0mjBjvy3RpJ1G7AAkQdYxUL3b2kDxxBG8R 8H4uw9ShE7fyy5Mp8NmJeflotFS1eUnShTaxgDhXoK0nAyZIu1CqFasNQSWhHBgXl0Q3 0pfXqb+2PIu6Rk2Ciox2u7sQQydQMOiNYY4uqMDVHa4+dYUu7VIg6DczWrfpt/ttumZx YYhw== MIME-Version: 1.0 X-Received: by 10.52.166.200 with SMTP id zi8mr274376vdb.38.1383270784973; Thu, 31 Oct 2013 18:53:04 -0700 (PDT) In-Reply-To: References: Date: Fri, 1 Nov 2013 12:53:04 +1100 Subject: Re: Python wart 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: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1383271244 news.xs4all.nl 15979 [2001:888:2000:d::a6]:38566 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:58226 On Fri, Nov 1, 2013 at 12:45 PM, Mark Lawrence wrote: > Quite often I type this > > print('Total of accounts %.2f', total) > > when I meant to type this > > print('Total of accounts %.2f' % total) > > Do I have to raise a PEP to get this stupid language changed so that it > dynamically recognises what I want it to do and acts accordingly? I feel your frustration there, especially since the usage you're attempting parallels C's printf function. But the parsing would be ambiguous - is it that any percent sign changes the meaning of print's arguments? Or is this some kind of DWIM system, where the meaning depends on whether the arguments "would work" if you used a percent sign? What you _could_ do, though, is decide that you will never EVER use print with multiple arguments. Then just do this: orig_print = print def print(fmt, *args, **kwargs): orig_print(fmt%args, **kwargs) Now your print function takes printf-style arguments. Note that this WILL error out if you have percent signs and no arguments; you may want to use "if args" to guard against that, or else just accept that it'll break if you do stuff that would be broken with printf. (You may want to play with functools.wraps for the benefit of docstrings and stuff... or maybe you don't care.) One of the advantages of print being a function is that you can actually do this :) With print as a statement, that option isn't there. ChrisA