Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!rt.uk.eu.org!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'syntax': 0.04; 'anyway.': 0.05; 'argument': 0.05; 'subject:Python': 0.06; 'assignment': 0.07; 'accepted,': 0.09; 'calls.': 0.09; 'function,': 0.09; 'instance.': 0.09; 'output,': 0.09; 'referenced': 0.09; 'statements': 0.09; 'sure,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; '(functions': 0.16; 'added.': 0.16; 'args,': 0.16; 'devs': 0.16; 'fixed;': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'function;': 0.16; 'kw:': 0.16; 'magic': 0.16; 'newline,': 0.16; 'shorthand': 0.16; 'stderr': 0.16; 'syntax,': 0.16; 'language': 0.16; 'wrote:': 0.18; "hasn't": 0.19; 'normally': 0.19; 'aug': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'creating': 0.23; 'replace': 0.24; 'cc:2**0': 0.24; 'nearly': 0.26; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'characters': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'ordinary': 0.31; 'file': 0.32; 'subject:the': 0.34; 'could': 0.34; 'something': 0.35; 'more,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'there': 0.35; 'opposed': 0.36; 'scheme': 0.36; 'done': 0.36; 'doing': 0.36; 'thanks': 0.36; 'should': 0.36; 'too': 0.37; 'requirements': 0.37; 'being': 0.38; 'skip:o 20': 0.38; 'that,': 0.38; 'anything': 0.39; 'sure': 0.39; 'space': 0.40; 'how': 0.40; 'then,': 0.60; 'providing': 0.61; 'simple': 0.61; "you'll": 0.62; 'information': 0.63; 'such': 0.63; 'grab': 0.64; 'more': 0.64; 'between': 0.67; 'special': 0.74; 'satisfied': 0.81; 'concept.': 0.84; 'magical': 0.91; 'to:none': 0.92 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=ICtnDqmGluHSDIEVo262mml72t2i/qnKDMCR053AjGY=; b=oSFlwCsCEfEdSZfgaR9rUHzhhDzJqp9wAgNKSIQsVRb5OBAWLe+KTFPbLYRmP58zDL sOGyanWnDllDadOUJO74bNXHSryaCZUns8JO8CzbIrbDjd3WsfpmgWL27PAUvq0rDNsG 836jeuYzmnDxbl5nPE9b81x1+6ulU1xwFzNvfR5DDBvJGWer6qXLzZ5dI01LX5+KDvOz DpWZtptJSjDbo493fo7zZGP9/bfiStjYRhEC2yw6MZIA6TKMtk+VSHrpT4Vg++W4iC9R eLIgGbBy+RJMB4DCGhfjxv4p/lLNxfDYnYYYyBrRHz+NalMFaaqv6WRnCbUzBmg3zyHW qXJQ== MIME-Version: 1.0 X-Received: by 10.42.107.75 with SMTP id c11mr19415737icp.60.1407020131730; Sat, 02 Aug 2014 15:55:31 -0700 (PDT) In-Reply-To: References: Date: Sun, 3 Aug 2014 08:55:31 +1000 Subject: Re: Python Programing for the Absoulte Beginner 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: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1407020139 news.xs4all.nl 2960 [2001:888:2000:d::a6]:57557 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75559 On Sun, Aug 3, 2014 at 8:41 AM, Seymore4Head wrote: >>If the book is for Python 2 and you have 3.3 it should be print("Game Over") > > Thanks > > I am sure they had a good reason to add using 2 more characters for > doing the same job. One more, since you'll normally have a space after the word "print" anyway. :) Language keywords are inflexible. Sure, it's nice and simple to do straightforward output, but when you want to send that to stderr instead of stdout, or change the separator between args, or change what's at the end of what's printed (a newline, normally), or anything like that, there needs to be special magical syntax added. Plus, it's nearly impossible to do a simple replacement of print with something else; pretty much the only way is to play with the code as it's being compiled. With a function, all that is fixed; there are standard ways of providing extra information (keyword arguments), you can replace print with any other function just by shadowing it, and all this can be done with perfectly normal syntax. This is how to tee print to a file as well as stdout: log_file = open("print.log","w") orig_print = print def print(*args, **kw): if "file" not in kw: orig_print(*args, **kw, file=log_file) orig_print(*args, **kw) So easy! You can grab a reference to the original print functionality with ordinary assignment (functions can be passed around and referenced by names; statements can't), you can replace it just by creating something else of the same name, and all its magic just comes through as arguments. There has been a move, now and then, to allow parens-free function calls. If some such scheme were accepted, you could then use the Python 2 syntax, and it would call the function; additionally, you could use the shorthand for any other function, too - "sys.exit 1" for instance. So far, there hasn't been a proposal that's satisfied all the requirements and given a compelling argument for acceptance, but I don't think the Python devs are philosophically opposed to the concept. ChrisA