Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: How to use "while" within the command in -c option of python?

Reply
Thread Tools

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

 
 
Dave Angel
Guest
Posts: n/a
 
      10-13-2012
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Re: How to use "while" within the command in -c option of python? Etienne Robillard Python 11 10-13-2012 10:09 PM
Re: How to use "while" within the command in -c option of python? Ned Deily Python 0 10-13-2012 02:17 AM
Re: How to use "while" within the command in -c option of python? Herman Python 0 10-13-2012 12:55 AM
How to use "while" within the command in -c option of python? Herman Python 0 10-12-2012 10:51 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57