Re: How to use "while" within the command in -c option of python?

Discussion in 'Python' started by Dave Angel, Oct 13, 2012.

  1. Dave Angel

    Dave Angel Guest

    On 10/12/2012 06:51 PM, Herman wrote:
    > python -c "import os; while True: print('hello')"
    > File "<string>", 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
     
    Dave Angel, Oct 13, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shawn Minisall

    while within while

    Shawn Minisall, Oct 27, 2007, in forum: Python
    Replies:
    11
    Views:
    531
  2. Herman
    Replies:
    0
    Views:
    173
    Herman
    Oct 12, 2012
  3. Etienne Robillard
    Replies:
    11
    Views:
    295
    Chris Angelico
    Oct 13, 2012
  4. Herman
    Replies:
    0
    Views:
    230
    Herman
    Oct 13, 2012
  5. Ned Deily
    Replies:
    0
    Views:
    188
    Ned Deily
    Oct 13, 2012
Loading...

Share This Page