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


Groups > comp.lang.python > #31108

for-loop on cmd-line

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <gvanem@broadpark.no>
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.03; 'newbie': 0.05; 'problem?': 0.07; 'python': 0.09; "%s'": 0.09; 'def': 0.10; 'to:name:python-list': 0.15; '"import': 0.16; 'file):': 0.16; 'syntaxerror:': 0.16; 'sys.path:': 0.16; '(in': 0.18; 'trying': 0.21; 'import': 0.21; '"",': 0.22; 'x-mailer:microsoft outlook express 6.00.2900.5931': 0.22; 'this:': 0.23; 'command': 0.24; "i'm": 0.29; 'file': 0.32; 'print': 0.32; 'to:addr:python-list': 0.33; 'list.': 0.35; 'charset:us-ascii': 0.36; 'skip:p 20': 0.36; 'turn': 0.36; 'to:addr:python.org': 0.39; 'subject:-': 0.40
MIME-version 1.0
Content-transfer-encoding 7BIT
Content-type text/plain; CHARSET=US-ASCII; format=flowed; reply-type=original
From Gisle Vanem <gvanem@broadpark.no>
To Python-list <python-list@python.org>
Subject for-loop on cmd-line
Date Thu, 11 Oct 2012 13:24:22 +0200
X-Priority 3
X-MSMail-priority Normal
X-Mailer Microsoft Outlook Express 6.00.2900.5931
X-MIMEOLE Produced By Microsoft MimeOLE V6.00.2900.6157
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.2043.1349954670.27098.python-list@python.org> (permalink)
Lines 23
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1349954670 news.xs4all.nl 6945 [2001:888:2000:d::a6]:33240
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:31108

Show key headers only | View raw


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):

  python -c "import sys,os; i=0; for p in sys.path: print('sys.path[%%2d]: %%s' %% (i, p)); i+=1"

But:
  File "<string>", line 1
    import sys,os; i=0; for p in sys.path: print('sys.path[%2d]: %s' % (i, p)); i+=1
                          ^
SyntaxError: invalid syntax

The caret is on the 'for'. What's the problem?

--gv

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


Thread

for-loop on cmd-line Gisle Vanem <gvanem@broadpark.no> - 2012-10-11 13:24 +0200
  Re: for-loop on cmd-line suzaku <satorulogic@gmail.com> - 2012-10-11 04:50 -0700
  Re: for-loop on cmd-line suzaku <satorulogic@gmail.com> - 2012-10-11 04:50 -0700

csiph-web