473,320 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

-c input

python -c "print 'hi'; for i in [1,2]: print i"

gives me an invalid syntax error, with the carat pointing to the end
of the word 'for'. But

python -c "print 'hi'; print 'i'"

works fine, as does

python -c "for i in [1,2]: print i"

What gives? Why can't 'for' appear after a semicolon? (Similar for
'while'.)

If there's some reason the 'for' can't be made to work after the
semicolon, is there some simple way to get a newline into the string
on the cmd line? (short of using 'echo' twice, or putting the
commands into a file)

(I've tested this in v2.3.3 under both CygWin and Linux.)
Jul 18 '05 #1
2 1621
Mike Maxwell <maxwell <at> ldc.upenn.edu> writes:
python -c "print 'hi'; for i in [1,2]: print i"

gives me an invalid syntax error, with the carat pointing to the end
of the word 'for'.
Semicolons are only allowed with simple statements, not compound statements:

http://docs.python.org/ref/compound.html

Note that:

stmt_list ::= simple_stmt (";" simple_stmt)* [";"]

So that you can only join simple statements with ";" characters.

If you want to insert newlines, in unix, you can do this like:
python -c "print 'hi'\

? for i in [1,2]:\
? print i"
hi
1
2

Note that the '\' characters cause unix to include the newline in the string,
instead of reading it as the command terminator. I don't know how to do this
in Windows.

Steve

Jul 18 '05 #2
Steven Bethard wrote:
Semicolons are only allowed with simple statements, not compound statements:

http://docs.python.org/ref/compound.html
Aargh, I'm getting perl envy...
Note that the '\' characters cause unix to include the newline in the string,
instead of reading it as the command terminator. I don't know how to do this
in Windows.


Yes, I tried this, but it doesn't seem to work inside (Gnu) makefiles,
either (at least I can't see how to do it).

Thanks for the answers, even if they weren't what I was hoping for :-).

Mike Maxwell
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: gotcha | last post by:
I have a little code to add multiple items to a shopping cart based page. This code works perfect, but it adds all of the info to the same input fields every time it loops. I need it to change...
3
by: david | last post by:
HI! Im trying to make "HTML form" into automatic. 1. If I get 18 numbers like: A B C D E F . . . . 2. How can I put those 18 numbers automatically into 6 numbers format like: A B C D E F
2
by: SophistiCat | last post by:
Hi, I am working on a computational program that has to read a number of parameters (~50) from an input file. The program contains a single class hierarchy with about a dozen member-classes or...
2
by: Cranky | last post by:
Ok, here is my scenario: I need to input numbers using my handheld IPAQ. I figured out how to create an online numeric keypad for inputting numbers into an input field, what I need to know is how...
3
by: acecraig100 | last post by:
I am fairly new to Javascript. I have a form that users fill out to enter an animal to exhibit at a fair. Because we have no way of knowing, how many animals a user may enter, I created a table...
3
by: cbradio | last post by:
Hi, I am having trouble developing a form in a restricted environment. My sample code is found below my message (sorry I don't have a URL). Basically, without a doctype, the form displays properly...
18
by: Diogenes | last post by:
Hi All; I, like others, have been frustrated with designing forms that look and flow the same in both IE and Firefox. They simply did not scale the same. I have discovered, to my chagrin,...
13
by: cront | last post by:
I have a problem to work on: we will ask user to input anything and we will put that back onto the standard output with all set of brackets removed. We will not remove any single bracket e.g. ...
1
by: tcertain | last post by:
I am totally duh at javascript although I have 2 books trying to learn it. I am trying to add values to a form and have a calculate total at end. this is my form script. I have hours at end of...
1
by: printline | last post by:
Hello All I'm quite new to xml vs. PHP, so i hope someone can help with an issue i have been struggeling with. I have an html form, that when submitted, it should create an xml file, and save...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.