Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!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; ';-)': 0.03; '21,': 0.07; 'continuation': 0.07; 'claimed': 0.09; 'literal': 0.09; 'newline': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'seemed': 0.09; 'spaces': 0.09; 'statements': 0.09; 'works.': 0.09; 'python': 0.11; 'def': 0.12; 'jan': 0.12; 'thread': 0.14; 'windows': 0.15; '"python': 0.16; '(it': 0.16; '(same': 0.16; 'a():': 0.16; 'added.': 0.16; 'b():': 0.16; 'command.': 0.16; 'ignoring': 0.16; 'presume': 0.16; 'processor,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'separated': 0.16; 'syntaxerror:': 0.16; 'unexpected': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'module': 0.19; 'meant': 0.20; 'written': 0.21; 'command': 0.22; 'appears': 0.22; 'example': 0.22; 'manual': 0.22; 'header:User-Agent:1': 0.23; 'typical': 0.24; 'header': 0.24; 'mon,': 0.24; 'file.': 0.24; '---': 0.24; 'second': 0.26; 'post': 0.26; 'header:X-Complaints- To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'chris': 0.29; 'feature': 0.29; 'character': 0.29; 'code': 0.31; 'easier': 0.31; 'lines': 0.31; '"",': 0.31; 'doc': 0.31; 'file:': 0.31; 'obscure': 0.31; 'quotes': 0.31; 'file': 0.32; 'run': 0.32; 'another': 0.32; 'says': 0.33; 'minimal': 0.33; 'third': 0.33; 'could': 0.34; 'problem': 0.35; 'possible.': 0.35; 'test': 0.35; 'but': 0.35; 'version': 0.36; 'really': 0.36; 'shows': 0.36; 'possible': 0.36; 'should': 0.36; 'so,': 0.37; 'follows:': 0.38; 'initially': 0.38; 'work?': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'how': 0.40; 'even': 0.60; 'remove': 0.60; 'received:173': 0.61; 'more': 0.64; 'line,': 0.68; 'prompt': 0.68; 'more?': 0.84; 'received:fios.verizon.net': 0.84; 'subject:commands': 0.84; '2013,': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: python -c commands on windows. Date: Mon, 21 Oct 2013 18:39:06 -0400 References: <1382390051.14804.36774153.32DD8EAD@webmail.messagingengine.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-59-117-133.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.0.1 In-Reply-To: <1382390051.14804.36774153.32DD8EAD@webmail.messagingengine.com> 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: 83 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1382395164 news.xs4all.nl 15968 [2001:888:2000:d::a6]:47609 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:57213 On 10/21/2013 5:14 PM, random832@fastmail.us wrote: > On Mon, Oct 21, 2013, at 16:47, Terry Reedy wrote: >> Manual says "-c >> Execute the Python code in command. command can be one or more >> statements separated by newlines, with significant leading whitespace as >> in normal module code." >> >> In Windows Command Prompt I get: >> C:\Programs\Python33>python -c "a=1\nprint(a)" >> File "", line 1 >> a=1\nprint(a) >> ^ >> SyntaxError: unexpected character after line continuation character >> (Same if I remove quotes.) >> >> How do I get this to work? > > Well, ignoring the "why would you want to" factor... Because it is claimed to be possible ;-) That particular example could be written in one line with ';'. But it is a minimal example that either shows the problem or obviously works. (IE, what we recommend people post ;-). I initially tried to test a version of Chris Angelico's code from another thread without writing it to a file: def a(): def b(): nonlocal c I also wanted to know if 'newline' in the doc meant a literal newline (it appears so, but it seemed impossible on Windows) rather than '\n' and if the problem was peculiar to Windows. And I need to know that to run "python -c ... " in a subproccess from Python. > this actually _is_ possible. Even on Windows .. I presume this is easier on *nix. > C:\>python -c a=1^ > More? > More? print(a) > 1 > > You can put quotes around any part of the command you need spaces in, > but you _cannot_ have the ^ in quotes. So, with quotes, it would be as > follows: > > C:\>python -c "a='1 2'"^ > More? > More? print(a) > 1 2 Spaces would be typical for a compound statememt header line. For a third line, the second should have ^ added. > This is a very obscure feature of the command processor, Really obscure ;-) > and I don't know if it works inside a batch file. It does: ---tem.bat python -c "def f(a):"^ " print(a+1)"^ f(2) ---Command Prompt C:\Programs\Python33>\Users\Terry\Documents\tem C:\Programs\Python33>python -c "def f(a):" " print(a+1)" f(2) 3 --- 3 lines echoed (they could have been suppressed) plus output. -- Terry Jan Reedy