top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

python -c commands on windows.

+2 votes
85 views

Manual says "-c 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:ProgramsPython33>python -c "a=1nprint(a)"
 File "", line 1
 a=1nprint(a)
 ^
SyntaxError: unexpected character after line continuation character
(Same if I remove quotes.)

How do I get this to work?

posted Oct 21, 2013 by Abhay Kulkarni

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

2 Answers

+1 vote

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.

answer Oct 21, 2013 by Garima Jain
+1 vote

From the odd workarounds department (not tested on Windows):

$ python3 -c "exec('a=1nprint(a)')"
1
answer Oct 22, 2013 by Naveena Garg
Similar Questions
0 votes

I want to install sip on windows bit using python 32 bit.
I download sip from this link https://www.riverbankcomputing.com and I try to install from cmd line :

C:WINDOWSsystem32>cd C:UsersusernameDesktopsip-4.17

C:UsersusernameDesktopsip-4.17>python configure.py install
and take that error any idea ?

This is SIP 4.17 for Python 2.7.11 on win32.
Error: Unsupported macro name specified. Use the --show-build-macros flag to see a list of supported macros.

+3 votes

I'm new to Python. I downloaded the 64-bit build of Python 2.7.10 from www.python.org/downloads/release/python-2710. I run Windows 7 Pro on a Dell PC.

I find that the installation package creates a folder called "Python 2.7" in my Start menu, with both a command prompt and IDLE GUI options.

I hold my scripts in another directory that is parallel to but not under the one where Python 2.7 resides, so I set the Environment Variable PYTHONPATH to include the directory where my scripts reside. Unfortunately, I am unable to reach them in either the IDLE GUI or the "Python command line" in that folder in my start menu. The only way I have managed to run Python scripts is to open an ordinary command prompt from Accessories, navigate to the directory with the scripts, and run python from the command prompt in that directory.

Can anyone let me know what I'm not doing that I should be doing to run Python and my scripts from the parallel directory under the GUI or the command line from the start menu folder ?

+2 votes

I want to install Python on a PC with the 64 bit version of Windows 7. I want Python to be able to use as much as possible of the RAM.

When I install the 64 bit version of Python I find that sys.maxint == 2**31 - 1 Whereas the Pythpon installed on my 64 bit linux system returns sys.maxint == 2**63 - 1.

It looks to me as though 32 and 64 bit versions of Python on 64 bit Windows are both really 32 bit Python, differing only in how they interact with Windows. So I wouldnt expect 64 bit Python running on 64 bit Windows to allow the large data struictures I could have with 64 bit Python running on 64 bit linux.

Is that true?I have spent a couple of hours searching for a definitive description of the difference between the 32 and 64 bit versions of Python for Windows and haven't found anything.

+1 vote

I understand there have been changes to the way that extensions are supposed to be built for windows. Is there any user documentation regarding these changes?

Last time I looked the appropriate Visual Studio hadn't been release so I guess I will need to use my MSDN skills (or incantations) to first get that installed.

+1 vote

How can write a python script which will execute some in gui not being lost processed....?

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...