Skip to main content


Showing posts from August, 2013

Python: dicts vs. classes

I like to "keep it simple stupid" when I'm coding Python. I use classes, but I don't try to shove everything into classes. When all you need is a dict or a list, use a dict or a list. However, I'm coming to think that if you have a bunch of objects that look like the following:books = [{ "authors": ["Neil Gaiman"], "title": "American Gods", "isbn": "9780062113450" }]Then it might be time to use a class rather than a dict. In this case, I'd create a class called Book, but I'd put Book instances into a simple list.

Python: One More Example of How PyCharm is Psychic

I had the following line in my Python code:if self._lookup_unallocated(current_allocation_state, key) > 0:I wanted to change it to:unallocated = self._lookup_unallocated(current_allocation_state, key) if unallocated > 0:Hence, I highlighted the expression, right clicked, refactor, extract, variable. It did the refactoring and automatically guessed that I wanted to name the variable "unallocated"! Presumably, it guessed based on the name of the method I was calling. Nonetheless, it's like it read my mind!

Books: Treading on Python

I just received my copy of Treading on Python! I was the technical editor :) There are two things that are great about this book. First, Matt Harrison's a really good Python programmer, and his writing is very crisp. Secondly, the book is really short! It's weighs in at a mere 183 pages!So if you're reading this, Matt, congratulations, and thanks for letting me part of your book!