I began learning Python a little time ago, and I got the first problem. Here's the code:
fh = open('/usr/share/dict/words')
for line in fh.readlines():
print(line, end='')
When I execute it in the Terminal (OS X), it tells me invalid syntax error where end equal sign is placed. What's the problem here? Didn't find the solution...
I installed Python 3.3.0 from this page, Python 3.3.0 Mac OS X 64-bit/32-bit x86-64/i386 Installer
Sorry for so nooby questions :(
Your terminal is probably using Python2.x
Try using the command python3 yourfilename.py
To see which Python version is the standard on your terminal just type python
You should see something like this:
Python 2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
To make your code work with 2.x you can use print without the parantheses:
print "Python", "yay!"
The Python 3 installer does not make Python 3 the default Python (if it did, it would break a ton of stuff, because very few Python scripts are Python 3 compatible). So to get Python 3, you should execute your script as python3 script.py, or add #!/usr/bin/env python3 to the top of the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With