There is no output for `python.exe -c 'print (" hello ")' '

I am trying to learn python and stumbled upon what seems like another silly mistake on my part.

With version 2.7.3, which I downloaded from python.org , I get no output for a simple program with -c . I get output with 2.6.8 output from cygwin.

What am I missing?

 > c:\Python27\python.exe --version Python 2.7.3 > c:\Python27\python.exe -c 'print("hello")' > c:\Python27\python.exe Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print("hello") hello >>> exit() > c:\cygwin\bin\python2.6.exe --version Python 2.6.8 > c:\cygwin\bin\python2.6.exe -c 'print("hello")' hello > c:\cygwin\bin\python2.6.exe Python 2.6.8 (unknown, Jun 9 2012, 11:30:32) [GCC 4.5.3] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> exit() 
+6
source share
1 answer

Try this without the single quotes around the program:

 python -c print(\"hello\") 

With single quotes, I assume that it interprets the input as a string, so printing is not performed. You also need to avoid double quotes in the program itself.

Edit:

You do not need to avoid single quotes, so you can do this instead:

 python -c print('hello') 

or

 python -c "print('hello')" 

(which is the original example, only with the replacement of quote types)

+5
source

All Articles