Received: by 10.180.84.74 with SMTP id w10mr3127203wiy.4.1350352649722; Mon, 15 Oct 2012 18:57:29 -0700 (PDT) Path: q10ni65138206wif.0!nntp.google.com!feeder3.cambriumusenet.nl!feed.tweaknews.nl!94.232.116.11.MISMATCH!feed.xsnews.nl!border-1.ams.xsnews.nl!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news.panservice.it!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-l...@python.org Delivered-To: python-l...@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'syntax': 0.03; 'languages,': 0.04; '"""': 0.05; 'merging': 0.07; 'subject:How': 0.09; 'python': 0.09; 'os;': 0.09; 'subject:command': 0.09; 'subject:while': 0.09; 'windows,': 0.09; 'subject:python': 0.11; '"import': 0.16; 'code?': 0.16; 'herman': 0.16; 'oct': 0.16; 'rem': 0.16; 'script?': 0.16; 'statement.': 0.16; 'syntaxerror:': 0.16; 'true:': 0.16; 'wrote:': 0.17; 'shell': 0.18; 'appropriate': 0.20; 'followed': 0.20; 'file.': 0.20; 'trying': 0.21; 'import': 0.21; 'thanks.': 0.21; '"",': 0.22; 'somewhere': 0.24; 'command': 0.24; 'script': 0.24; 'header:In-Reply-To:1': 0.25; 'separate': 0.27; 'question': 0.27; 'message-id:@mail.gmail.com': 0.27; 'source': 0.29; 'probably': 0.29; 'fri,': 0.30; 'keyword': 0.30; 'code': 0.31; 'file': 0.32; 'quickly': 0.32; 'running': 0.32; 'problem': 0.33; 'to:addr:python-list': 0.33; 'monitor': 0.33; 'received:google.com': 0.34; 'wrong': 0.34; 'pm,': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; '12,': 0.36; 'subject:" ': 0.36; "i'll": 0.36; 'two': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'nothing': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'hello,': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'your': 0.60; 'first': 0.61; 'making': 0.64; 'choose': 0.65; 'press': 0.71; "'while'": 0.84; 'subject: -': 0.84; 'angel': 0.93; 'imagine': 0.96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=yOM4kYKXqVpXVeKuhRCcgBjJ0xLhWnV600O26VKXVJQ=; b=nnEhUZ2glGRM1ObJ7CMzoMUpgnhuCj2AuKljbVobwewSINraHNkKyTy9WDDaNu1bti DeGlZ05jHh2NRKPuu8qf/W354SciKDjz/9Y8ndlsFkkZxzf4vsAnoq0k4H64rhx+v94d hV9vzPGgb8T0FG4mUxVzlp8Jq8Vu9wZzre+5N2e2UyNH6UMDQ5lCz177S4v/Ba6w1x0S L3HEgWXB6faRRb0wRyG2+s0G7DarUkWSfx3PiuU388+STTxQiQ3Dh4eQw9RM3RoJP8bv t3L379ujpsOzeAX4I21kHQt5PlWsFH0I6bgN9xp2tSm1oTlXnJfIqeluj7ICsDs8acYz LdrQ== MIME-Version: 1.0 In-Reply-To: <5078B5FC.1030...@davea.name> References: <5078B5FC.1030...@davea.name> Date: Fri, 12 Oct 2012 17:55:49 -0700 Subject: Re: How to use "while" within the command in -c option of python? From: Herman To: python-l...@python.org X-BeenThere: python-l...@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: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1350089753 news.xs4all.nl 6881 [2001:888:2000:d::a6]:47760 X-Complaints-To: ab...@xs4all.nl Bytes: 5048 Content-Type: text/plain; charset=ISO-8859-1 I was just trying to do in a shell to quickly monitor a file. Imagine instead of printing hello, it is "os.system("cat somefile")", etc. Look like it works if i press an enter after the "import xxx". Thanks. On Fri, Oct 12, 2012 at 5:29 PM, Dave Angel wrote: > On 10/12/2012 06:51 PM, Herman wrote: >> python -c "import os; while True: print('hello')" >> File "", line 1 >> import os; while True: print('hello') >> ^ >> SyntaxError: invalid syntax > See the recent thread: > "for-loop on cmd-line" > > The problem has nothing to do with the command line, it's caused by > trying to use a keyword 'while' somewhere other than the beginning of > the statement. > > I'll ask you the same question I had: why do you bother? What's wrong > with making a separate file for the source code? > > But as for solutions, first question is what OS you're running on. If > not Windows, you can probably use \n at appropriate points. > > If that's not good enough, what about simply running the script instead > of a batch file? > > If that's not good enough, how about merging the two languages, with a > trick like starting the python code with rem = """ followed by the > shell script? > > There are many others, but we cannot choose without knowing your other > constraints. > > > > -- > > DaveA >