How to use "while" within the command in -c option of python?
Jussi Piitulainen
jpiitula at ling.helsinki.fi
Sat Oct 13 13:43:46 EDT 2012
Chris Angelico writes:
> Here's a side challenge. In any shell you like, start with this
> failing statement, and then fix it without retyping anything:
>
> sikorsky at sikorsky:~$ python -c "a=1; if a: print(a)"
> File "<string>", line 1
> a=1; if a: print(a)
> ^
> SyntaxError: invalid syntax
>
> In bash, I was unable to insert a newline into the quoted string. My
> only option was to backspace everything after the point where I
> wanted the newline, then hit enter, then retype the if. I'm curious
> to know if that's simply because I didn't think of (some bash
> feature), or alternatively, if there's another shell that would have
> made this easy.
C-v C-j inserts a newline for me, in bash.
More information about the Python-list
mailing list