Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'syntax': 0.04; 'anyway.': 0.05; 'cpython': 0.05; 'interpreter': 0.05; 'python)': 0.05; 'differently': 0.07; 'statements': 0.09; 'subject:script': 0.09; 'subject:How': 0.10; 'cc:addr:python- list': 0.11; 'python': 0.11; 'behave': 0.16; 'buffer,': 0.16; 'constructs': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'happily': 0.16; 'interpreter;': 0.16; 'ironpython': 0.16; 'repl': 0.16; 'semicolon': 0.16; 'separated': 0.16; 'subject:run': 0.16; 'valid.': 0.16; 'followed': 0.16; 'wrote:': 0.18; '(but': 0.19; '>>>': 0.22; 'proposed': 0.22; 'shell': 0.22; 'cc:addr:python.org': 0.22; 'creating': 0.23; '(by': 0.24; 'instance,': 0.24; 'interpret': 0.24; "shouldn't": 0.24; 'cc:2**0': 0.24; 'this:': 0.26; 'post': 0.26; 'header:In- Reply-To:1': 0.27; 'point': 0.28; 'chris': 0.29; 'am,': 0.29; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'gives': 0.31; "d'aprano": 0.31; 'responded': 0.31; 'spam,': 0.31; 'steven': 0.31; 'though.': 0.31; 'file': 0.32; 'option': 0.32; 'quite': 0.32; 'running': 0.33; 'beginning': 0.33; 'fri,': 0.33; 'not.': 0.33; 'subject:from': 0.34; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'cancel': 0.36; 'doing': 0.36; 'subject:?': 0.36; 'should': 0.36; 'being': 0.38; 'fact': 0.38; 'rather': 0.38; "couldn't": 0.39; 'commands': 0.60; 'skip:* 10': 0.61; 'name': 0.63; '30,': 0.65; 'legal': 0.71; 'technically': 0.84; 'shell,': 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=LfaJZ/Q3HIEfl0voqE4i5TflrwfXqX66jkTd+HzcWtA=; b=K/z77QYAEhnIN5Vkz+aY3pfbFBm62+2vIBL8zM5817q9pGrihGNK5xBT1DYkxpkrsQ CAuH9U97ZMR1Pj6XCMW4KckxZBiwA+GmJT7ih6nlOiKBl3pkxa46KhFH+BFutX/0Vf4L syXWowLPYMJi9fusJGaoE4lBDkKtUXAeZ4NFHD+OlLgWA4P0EfB3jkvZ1+u2weu+gTr2 iH/v1Ftu4p8c8u+11crU1Lonf37vWO4mg5OQJXcdm1ySfP/SUfqYmcUSjpzY1d3PSeOS fT4ffGbYq+2kVWZO6PHxQkzGQqox1/hI9Ka7l7lX77Z+gMJpyc+LVxWbKzDYVBDJxhDT EJIg== MIME-Version: 1.0 X-Received: by 10.58.85.3 with SMTP id d3mr10814371vez.34.1401415467641; Thu, 29 May 2014 19:04:27 -0700 (PDT) In-Reply-To: <5387e3b1$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <6e96c4c4-17db-464b-b291-816c534b70c4@googlegroups.com> <5386a7e2$0$11109$c3e8da3@news.astraweb.com> <5387d1c4$0$29978$c3e8da3$5496439d@news.astraweb.com> <5387e3b1$0$29978$c3e8da3$5496439d@news.astraweb.com> Date: Fri, 30 May 2014 12:04:27 +1000 Subject: Re: How to run script from interpreter? 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: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1401415475 news.xs4all.nl 2898 [2001:888:2000:d::a6]:38635 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:72271 On Fri, May 30, 2014 at 11:49 AM, Steven D'Aprano wrote: > On Fri, 30 May 2014 10:46:34 +1000, Chris Angelico wrote: > >> On Fri, May 30, 2014 at 10:33 AM, Steven D'Aprano >> wrote: >>> (By the way, ; won't work for a Python shell, because ;spam already is >>> valid Python syntax: it's an empty statement followed by the statement >>> spam, separated by a semicolon.) >> >> That's not really a problem, though. It's not going to stop you from >> doing something actually *useful*, and the fact that the semicolon could >> be syntactically valid isn't going to come into it, because the REPL >> would swallow it anyway. > > The point is that *syntactically valid* Python statements should not > behave differently when running inside the shell or not. I thought > that ;statement was syntactically valid -- but I was wrong. The vanilla > CPython interactive interpreter gives a syntax error, as do IronPython > and Jython. Huh. I responded to your post on the unchecked assumption that ";spam" was syntactically valid. I'm still of the opinion that technically valid (but not useful) constructs are allowed to be swallowed by an interactive interpreter; for instance, it's perfectly valid to write this: >>> x = (1 . imag) But quite a few interpreters (though not Python) take a dot on its own line to mean "flush the buffer, cancel my current command". I couldn't find a way to do this in Python, but if someone proposed adding it, the fact that the above is syntactically legal shouldn't be a proposal blocker. It's on par with creating a file with a name beginning with a hyphen, and then fiddling around with various commands as you try to manipulate it (tip: "rm ./-r" works); programs will happily interpret "-r" as an option rather than a file name, without being concerned that it's technically legal. ChrisA