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


Groups > comp.lang.python > #31115

Re: for-loop on cmd-line

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <maniandram01@gmail.com>
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; 'newbie': 0.05; 'sys': 0.05; 'exit': 0.07; 'lines.': 0.07; 'skip:\\ 10': 0.07; 'scripts': 0.09; 'python': 0.09; "%s'": 0.09; "'''": 0.09; '@echo': 0.09; 'comment,': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; '(the': 0.15; 'weird': 0.15; '"exit': 0.16; 'echo': 0.16; 'exploits': 0.16; 'file):': 0.16; 'oct': 0.16; 'rem': 0.16; 'sys.path:': 0.16; 'wrote:': 0.17; 'thu,': 0.17; '(in': 0.18; 'windows': 0.19; 'variable': 0.20; '+0200': 0.20; 'file.': 0.20; 'trying': 0.21; 'import': 0.21; 'cc:2**0': 0.23; 'this:': 0.23; 'cc:no real name:2**0': 0.24; 'command': 0.24; 'script': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'dos': 0.27; 'easiest': 0.27; 'actual': 0.28; 'chris': 0.28; 'run': 0.28; "i'm": 0.29; 'thursday,': 0.30; 'code': 0.31; 'not.': 0.32; 'print': 0.32; '11,': 0.33; 'quotes': 0.33; 'another': 0.33; 'received:google.com': 0.34; 'done': 0.34; 'compared': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'list.': 0.35; 'but': 0.36; 'closing': 0.36; 'should': 0.36; 'skip:p 20': 0.36; 'turn': 0.36; 'october': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'fact': 0.38; 'sure': 0.38; 'called': 0.39; 'subject:-': 0.40; 'your': 0.60; 'most': 0.61; "you'll": 0.62; 'batch.': 0.84; '"one': 0.91
Newsgroups comp.lang.python
Date Thu, 11 Oct 2012 06:16:25 -0700 (PDT)
In-Reply-To <mailman.2047.1349961261.27098.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=122.167.82.56; posting-account=uPFZNQoAAAAm9w7z13q1SjWNKNjztdcD
References <E7295A9F2EFF4FD0A64C1225370AAC56@dev.null> <20121011081607.46014e3d@dilbert> <mailman.2047.1349961261.27098.python-list@python.org>
User-Agent G2/1.0
X-Google-Web-Client true
X-Google-IP 122.167.82.56
MIME-Version 1.0
Subject Re: for-loop on cmd-line
From Ramchandra Apte <maniandram01@gmail.com>
To comp.lang.python@googlegroups.com
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org
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>
Message-ID <mailman.2048.1349961393.27098.python-list@python.org> (permalink)
Lines 114
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1349961393 news.xs4all.nl 6843 [2001:888:2000:d::a6]:35797
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:31115

Show key headers only | View raw


On Thursday, 11 October 2012 18:44:44 UTC+5:30, Chris Angelico  wrote:
> On Thu, Oct 11, 2012 at 11:16 PM, D'Arcy J.M. Cain <darcy@druid.net> wrote:
> 
> > On Thu, 11 Oct 2012 13:24:22 +0200
> 
> > Gisle Vanem <gvanem@broadpark.no> wrote:
> 
> >
> 
> >> Hello list. I'm a newbie when it comes to Python.
> 
> >>
> 
> >> I'm trying to turn this:
> 
> >>
> 
> >>  def print_sys_path():
> 
> >>     i = 0
> 
> >>     for p in sys.path:
> 
> >>       print ('sys.path[%2d]: %s' % (i, p))
> 
> >>       i += 1
> 
> >>
> 
> >> into a one-line python command (in a .bat file):
> 
> >
> 
> > Is "one liner" an actual requirement or is the requirement to run it
> 
> > from the command line?
> 
> >
> 
> > python -c "
> 
> > import sys
> 
> > i = 0
> 
> > for p in sys.path:
> 
> >   print('sys.path[%2d]: %s' % (i, p))
> 
> >   i+=1
> 
> > "
> 
> >
> 
> > I don't know if this works on Windows or not.
> 
> 
> 
> It doesn't, I just tested it. Windows batch is appallingly crude
> 
> compared to a modern Unix shell; you may be able to find a way to get
> 
> around this, but the easiest solution for most batch files is going to
> 
> be an actual Python script file. You may be able to overlay your batch
> 
> and Python scripts with a trick like this:
> 
> 
> 
> rem = '''
> 
> @echo off
> 
> echo This is batch
> 
> \python32\python %0
> 
> echo All done
> 
> exit /b
> 
> rem '''
> 
> import sys
> 
> print("This is Python")
> 
> for i,p in enumerate(sys.path):
> 
> 	print('sys.path[%2d]: %s' % (i, p))
> 
> print("Python done")
> 
> 
> 
> You'll have a variable in Python called 'rem' which contains all your
> 
> batch code :) It exploits the fact that 'rem' makes a one-line
> 
> comment, but the triple quotes go across multiple lines. (The "exit
> 
> /b" should exit the batch script without closing cmd.exe - this is yet
> 
> another weird WEIRD wart in Windows batch. I'm pretty sure neither DOS
> 
> nor OS/2 batch required that parameter.)
> 
> 
> 
> ChrisA

What about the "Power" in PowerShell?

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


Thread

Re: for-loop on cmd-line Chris Angelico <rosuav@gmail.com> - 2012-10-12 00:14 +1100
  Re: for-loop on cmd-line Ramchandra Apte <maniandram01@gmail.com> - 2012-10-11 06:16 -0700
    Re: for-loop on cmd-line Chris Angelico <rosuav@gmail.com> - 2012-10-12 00:20 +1100
  Re: for-loop on cmd-line Ramchandra Apte <maniandram01@gmail.com> - 2012-10-11 06:16 -0700
    Re: for-loop on cmd-line wxjmfauth@gmail.com - 2012-10-11 09:24 -0700
      Re: for-loop on cmd-line Chris Angelico <rosuav@gmail.com> - 2012-10-12 03:32 +1100
      Re: for-loop on cmd-line Gisle Vanem <gvanem@broadpark.no> - 2012-10-11 18:49 +0200
      Re: for-loop on cmd-line Chris Angelico <rosuav@gmail.com> - 2012-10-12 03:58 +1100
      RE: for-loop on cmd-line "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-10-11 20:12 +0000
    Re: for-loop on cmd-line wxjmfauth@gmail.com - 2012-10-11 09:24 -0700

csiph-web