python -c commands on windows.

Peter Otten __peter__ at web.de
Tue Oct 22 03:31:46 EDT 2013


Terry Reedy wrote:

> Manual says "-c <command>
>      Execute the Python code in command. command can be one or more
> statements separated by newlines, with significant leading whitespace as
> in normal module code."
> 
> In Windows Command Prompt I get:
> C:\Programs\Python33>python -c "a=1\nprint(a)"
>    File "<string>", line 1
>      a=1\nprint(a)
>                  ^
> SyntaxError: unexpected character after line continuation character
> (Same if I remove quotes.)
> 
> How do I get this to work?

>From the odd workarounds department (not tested on Windows):
 
$ python3 -c "exec('a=1\nprint(a)')"
1





More information about the Python-list mailing list