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: 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 To: Python-list 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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 "", 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