I’ve been learning Python for a few months and am starting to use it at work, so I thought it was about time to read a book about Python. This book has been excellent. No only does it follow format of the time-honoured ‘Effective’ series pioneered by Scott Meyers, it also features practical, useful code examples. In particular, his JsonMixin class was immediately relevant to some work I’ve been doing to generically serialise to/from JSON documents – see Item 26 “Use Multiple Inheritance Only for Mix-In Utility Classes”.
The author has also taken the time to record hours of video lessons for Safari Online subscribers, so you can view additional material as he works through the items in the book.
I recently wrote about starting to learn Python using HackerRank exercises. I’ve also been recommended Paul Ross’s training exercises. I think you need to have covered some introduction to the language first of all, but these exercises are accompanied by useful tips and solutions, which is very helpful. I also downloaded PyTest as per the recommendations – it’s easy to install (just download the zip from github and run “python setup.py install” as an admin) and provides neat unit testing for Python applications.
Having learnt enough Swift to write a neat watch face app for Apple Watch this summer, I thought I’d turn my attention to learning some Python.
Firstly, I wanted a way to edit Python commands in a decent editor and run them. It appears that Xcode doesn’t support this out of the box, but this handy StackOverflow question gives the details on how to set it up.
Secondly, I wanted a series of challenges/tutorials to walk through the basic syntax of Python. HackerRank.com is very good for this sort of thing and has a decent set of exercises to work through.
My first bug was very revealing about the differences between Python and strongly-typed languages like F# and C++:
N = int(raw_input().strip())
if (n > 10):
print( "big" )
elif ( N < 0 ):
print( "negative" )
print( "normal" )
The Python Interpreter doesn’t give an error because of the typo “n > 10” instead of “N > 10” – it just carries on regardless!
Finally, Python Software Foundation seems like a good reference site with lots of examples.
See also the next post in this series.