Best Practices for Compatible Python 2 and 3 Code

Posted by Bob on Wed 22 March 2017 in Tools • Tagged with 2vs3, tox, six, python-modernize, porting, future, 2to3, coverage, futurize, caniusepython3, pip, Requests, Werkzeug • 3 min read

95% of most popular Python packages support Python 3. Maybe you are lucky and get to start fresh using Python 3. However as of last year Python 2.7 still reigns supreme in pip installs and at a lot of places 2.x is the only version you get to work in. I think writing Python 2 and 3 compatible code is an important skill, so lets check what it entails.


Continue reading

10 Tips to Get More out of Your Regexes

Posted by Bob on Wed 15 March 2017 in Tips • Tagged with regex, tips, parsing, regular expressions, findall • 5 min read

Regular expressions can be arcane, yet when used with care they can also be very powerful. In this post a couple of tips to get more out of your regexes when using Python's re module.


Continue reading

Module of the Week - Requests-cache for Repeated API Calls

Posted by Bob on Tue 14 March 2017 in Modules • Tagged with requests, cache, APIs, package • 2 min read

Today a quick article on a nice caching module when working with APIs: Requests-cache.


Continue reading

Simple API Part 2 - Building a Deep Work Logger with Flask, Slack and Google Docs

Posted by Bob on Fri 10 March 2017 in Tools • Tagged with Flask, Slack, Google docs, Heroku, APIs, pygsheets, git, commands, productivity, learning • 3 min read

After Simple API - part 1 a more practical app in this part 2 tutorial: a Deep Work logger integrating Google docs and Slack, including deployment of the app to Heroku.


Continue reading

Don't let mutability of compound objects fool you!

Posted by Bob on Tue 07 March 2017 in Concepts • Tagged with list, mutable, copy, deepcopy • 3 min read

In this article I explain the difference between shallow versus deep copy with a working example. It's an important concept when working with compound objects.


Continue reading

How To Build a Simple API with Flask and Unit Test it

Posted by Bob on Fri 03 March 2017 in Concepts • Tagged with APIs, Flask, REST, curl, testing, unittest, inventory • 3 min read

In this post I will create a simple API with Flask and test it with curl and unit testing its HTTP methods.


Continue reading

5 tips to speed up your Python code

Posted by Bob on Tue 21 February 2017 in Best practices • Tagged with performance, data structures, pythonic, generators, map, builtin, algorithms, regex, patterns • 5 min read

In this post I will give you 5 tips to speed up your code.


Continue reading

Visualizing website and social media metrics with matplotlib [notebook]

Posted by Bob on Wed 08 February 2017 in Data • Tagged with matplotlib, visualization, histogram, jupyter, data analysis, data science, socialmedia, googletrends • 12 min read

in this notebook i use matplotlib.pyplot to create simple yet powerful visualizations of pybites twitter activity, our blog's tag usage and our website traffic. Lastly I use Google trends to see popularity of various social media.


Continue reading

Python Tricks book review

Posted by Bob on Tue 31 January 2017 in Books • Tagged with review, tricks, tips, pythonic, oop, ABC, dicts, cleancode • 2 min read

A review of Dan Bader's Python tricks book.


Continue reading

Python's data model by example

Posted by Bob on Wed 25 January 2017 in Concepts • Tagged with datamodel, oop, magicmethods, builtin, pythonic, iterators, slicing • 14 min read

After last post on OOP a logical follow-up is Python's data model. We use the great Fluent Python book to code up an example of our own, showing the powerful way you can leverage this data model. You can download the notebook here.


Continue reading