Path: csiph.com!usenet.pasdenom.info!news.franciliens.net!fdn.fr!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2a.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'syntax': 0.04; 'subject:Python': 0.06; 'imported': 0.09; 'interpreted': 0.09; 'lawrence': 0.09; 'measure': 0.09; 'spaces': 0.09; 'works.': 0.09; 'python': 0.11; '"from': 0.16; '__future__': 0.16; 'bracket': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'optional': 0.16; 'redundant': 0.16; 'statement.': 0.16; 'subject: \n ': 0.16; 'subject:object': 0.16; 'whitespace.': 0.16; 'wrote:': 0.18; 'import': 0.22; 'saying': 0.22; 'print': 0.22; 'header:User- Agent:1': 0.23; 'error': 0.23; "haven't": 0.24; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'thus': 0.29; 'subject:that': 0.31; 'subject:with': 0.35; 'but': 0.35; 'add': 0.35; "didn't": 0.36; 'message-id:@gmail.com': 0.38; 'same.': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'space': 0.40; 'expression': 0.60; "you're": 0.61; 'between': 0.67; 'hand': 0.80; 'future,': 0.83; 'subject:made': 0.84; 'treats': 0.84 X-Virus-Scanned: amavisd-new at torriefamily.org Date: Sun, 14 Dec 2014 22:27:05 -0700 From: Michael Torrie User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131118 Thunderbird/17.0.11 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Python console rejects an object reference, having made an object with that reference as its name in previous line References: <01937423-e700-4825-a502-568dcb2d5324@googlegroups.com> <41c32aed-315a-43df-9dc6-380d0ecc3425@googlegroups.com> <548e4837$0$13012$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1418621243 news.xs4all.nl 2885 [2001:888:2000:d::a6]:33007 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:82546 On 12/14/2014 07:47 PM, Mark Lawrence wrote: > I didn't realise that Python was so smart. It can indicate a syntax > error at the final 't' in print before it gets to the opening bracket > that is required for the print function in Python 3 (and Python 2 if > you're using "from __future__ import print_function")? Not really. Python2 just interprets "print (value)" as an expression to the print statement. It's like saying "a=(value)" and then "print a". Redundant but works. However "print(value)" is interpreted as a function call, and if you haven't imported it from future, it will error out on Python2. Python 3, on the other hand treats spaces between a function and its opening paren to be optional whitespace. Thus to python3, "print(value)" and "print (value)" are the same. So if you always put a space between print and (value) you can achieve some measure of cross-version compatibility with print. However by including print_function from __future__ you are guaranteeing you won't forget to add the parens.