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


Groups > comp.lang.python > #31108

for-loop on cmd-line

From Gisle Vanem <gvanem@broadpark.no>
Subject for-loop on cmd-line
Date 2012-10-11 13:24 +0200
Newsgroups comp.lang.python
Message-ID <mailman.2043.1349954670.27098.python-list@python.org> (permalink)

Show all headers | 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