python -c commands on windows.
random832 at fastmail.us
random832 at fastmail.us
Mon Oct 21 17:14:11 EDT 2013
On Mon, Oct 21, 2013, at 16:47, 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?
Well, ignoring the "why would you want to" factor... this actually _is_
possible.
C:\>python -c a=1^
More?
More? print(a)
1
You can put quotes around any part of the command you need spaces in,
but you _cannot_ have the ^ in quotes. So, with quotes, it would be as
follows:
C:\>python -c "a='1 2'"^
More?
More? print(a)
1 2
This is a very obscure feature of the command processor, and I don't
know if it works inside a batch file.
More information about the Python-list
mailing list