Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #57208

Re: python -c commands on windows.

From random832@fastmail.us
References <l443sd$er5$1@ger.gmane.org>
Subject Re: python -c commands on windows.
Date 2013-10-21 17:14 -0400
Newsgroups comp.lang.python
Message-ID <mailman.1323.1382390053.18130.python-list@python.org> (permalink)

Show all headers | View raw


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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: python -c commands on windows. random832@fastmail.us - 2013-10-21 17:14 -0400

csiph-web