i just started learning Python (w no prior programing experience whatsoever) so i was asked to get TextWrangler and type: print "hello world"
(of course) and then RUN it through Terminal app on Mac. i was also asked to use Python 2.7 NOT Python 3!!! but when i wrote the line as i was told to on the video print "Hello World"
the Terminal app showed a syntax err! when i wrote the line print ("hello world")
then it went through with no problem and was executed by Terminal. why is my python 2.7 acting like python 3, if i can put it that way? When i type python --version
in terminal it shows that i run 2.7 version. Thanks.
Asked
Active
Viewed 112 times
-2

elethan
- 16,408
- 8
- 64
- 87
-
Try to run `python --version` in console, and what does it say? – zhm Jan 20 '17 at 03:42
-
1Did you import `from __future__ import print_function`? – Alex Fung Jan 20 '17 at 03:51
-
1If you could show a full transcript of the shortest possible REPL session showing this behavior, **including the banner that Python prints when started with the active version number**, that would be helpful. (It would also answer the question Alex asked, since such a transcript would show everything you'd entered necessary to cause the error). – Charles Duffy Jan 20 '17 at 03:55
-
...that way we'd know that the Python interpreter running `python --version` and the Python interpreter that gave you an error are the same one (you can have more than one version of Python installed on the same machine!) – Charles Duffy Jan 20 '17 at 03:57
-
your IDE is linked to python 3 somehow. Try `python -c "print 'hello world'"` – kilojoules Jan 20 '17 at 04:00
-
it's in the last sentence in my question, when i type python --version in terminal shows me Python 2.7.13 Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 12:39:47) – Anton Dimitrov Jan 20 '17 at 16:57
-
I have no idea what from __future__ import print_function is. do i run this line into Terminal or the text editor? kilojoules, when i run the line in terminal, hello world prints as next line. – Anton Dimitrov Jan 20 '17 at 16:59
1 Answers
-1
You can explicitly request the python 2 shell over conflicting versions in terminal like so:
alias python='python2'

Charles Kenney
- 360
- 3
- 12