Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #29512

Re: 'indent'ing Python in windows bat

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
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.03; 'args': 0.04; 'interpreter': 0.04; 'subject:Python': 0.05; 'continuation': 0.07; 'interpreted': 0.07; 'interpreter.': 0.07; 'raised': 0.07; 'strings.': 0.07; 'python': 0.09; 'output,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'stating': 0.09; 'terry': 0.09; 'unexpected': 0.09; 'thread': 0.11; 'interprets': 0.16; 'literal,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'statements,': 0.16; 'subject:windows': 0.16; 'syntaxerror:': 0.16; 'string': 0.17; 'wrote:': 0.17; 'fix': 0.17; 'passes': 0.17; 'jan': 0.18; '>>>': 0.18; 'code,': 0.18; 'windows': 0.19; 'followed': 0.20; 'putting': 0.20; 'suggested': 0.20; '"",': 0.22; 'either.': 0.22; 'latter': 0.22; 'insert': 0.23; 'seems': 0.23; 'command': 0.24; 'pass': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; '(which': 0.26; 'skip:" 20': 0.26; '(most': 0.27; 'am,': 0.27; 'recognized': 0.27; 'separate': 0.27; 'header:X-Complaints-To:1': 0.28; 'multiline': 0.29; 'prints': 0.29; 'unchanged': 0.29; 'character': 0.29; 'worked': 0.30; 'keyword': 0.30; 'code': 0.31; 'gets': 0.32; 'file': 0.32; 'running': 0.32; 'quotes': 0.33; 'traceback': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; 'along': 0.35; 'said,': 0.35; 'received:org': 0.36; 'but': 0.36; 'characters': 0.36; 'anything': 0.36; 'correctly': 0.37; 'itself': 0.37; 'does': 0.37; 'why': 0.37; 'files': 0.38; 'to:addr:python.org': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'first': 0.61; 'is.': 0.62; 'within': 0.64; 'smith': 0.71; 'received:fios.verizon.net': 0.84; 'not:': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: 'indent'ing Python in windows bat
Date Wed, 19 Sep 2012 14:18:26 -0400
References <mailman.3021.1347928001.27097.python-list@python.org> <5057C990.8080809@invtools.com> <k38vl8$u02$2@ger.gmane.org> <505803A9.4000409@davea.name> <mailman.870.1347973403.27098.python-list@python.org> <k3c2st$l6l$1@r03.glglgl.gl> <5059BA28.2090803@invtools.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-75-251-66.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120824 Thunderbird/15.0
In-Reply-To <5059BA28.2090803@invtools.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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.932.1348078726.27098.python-list@python.org> (permalink)
Lines 68
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1348078726 news.xs4all.nl 6904 [2001:888:2000:d::a6]:43894
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:29512

Show key headers only | View raw


On 9/19/2012 8:27 AM, David Smith wrote:

> but not:
> print('hi');if 1: print('hi')
>
> Chokes on the 'if'. On the surface, this is not consistent.

Yes it is. ; can only be followed by simple statements. The keyword for 
compound statememts must be the first non-indent token on a line. That 
is why I suggested at the beginning of the thread to insert '\n', 
stating correctly that it works for exec().

 >>> exec("print('hi');if 1: print('hi')")
Traceback (most recent call last):
   File "<pyshell#0>", line 1, in <module>
     exec("print('hi');if 1: print('hi')")
   File "<string>", line 1
     print('hi');if 1: print('hi')
                  ^
SyntaxError: invalid syntax
 >>> exec("print('hi');\nif 1: print('hi')")
hi
hi
 >>> exec("print('hi')\nif 1: print('hi')")
hi
hi

Someone raised the issue of whether the bat interpreter passes along the 
quoted string unchanged or if it interprets '\' or '\n' itself and in 
the latter case whether one to do anything so that python will see '\n' 
after any fiddling by the bat interpreter. It seems that \ is not 
interpreted within strngs by bat, but the problem is that the string is 
then seen by python as code, not as a string literal, and so python does 
not 'cook' it either. Running tem.bat from a command line (which echoes 
line from .bat), so I see the output, I get (Win7)

C:\Programs\Python33>python -c "print(1)\nif 1: print(2)"
   File "<string>", line 1
     print(1)\nif 1: print(2)
                            ^
SyntaxError: unexpected character after line continuation character

One gets the same response interactively from
 >>> print('hi')\nif 1: print('hi')
or
 >>> exec("print('hi')\\nif 1: print('hi')")

The fix is to quote and pass the exact code that worked above in the 
python shell, keeping in mind that the outer quotes must be the double 
quote characters recognized by windows.

C:\Programs\Python33>python -c "exec('print(1)\nif 1: print(2)')"
1
2

I did check that windows % interpolation of .bat args works within '' 
quoted strings. Change tem.bat to
python -c "exec('print(%1)\nif 1: print(2)')"
and calling 'tem 3' prints
3
2

That said, if you have many multiline statements, putting them in a 
separate file or files may be a good idea.

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: 'indent'ing Python in windows bat David Smith <davids@invtools.com> - 2012-09-18 09:03 -0400
  Re: 'indent'ing Python in windows bat Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-09-19 11:22 +0200
    Re: Re: 'indent'ing Python in windows bat David Smith <davids@invtools.com> - 2012-09-19 08:27 -0400
    Re: 'indent'ing Python in windows bat Terry Reedy <tjreedy@udel.edu> - 2012-09-19 14:18 -0400
    Re: Re: 'indent'ing Python in windows bat David Smith <davids@invtools.com> - 2012-09-19 16:09 -0400

csiph-web