The Python community is alive and growing at a staggering rate. It is an active community that has many benefits. New people bring new ideas, fresh perspectives, and different levels of experience.
One such benefit is the proliferation of packages. If you need functionality, there is a good chance that someone else needed it before you. The beauty of the Python community is that most of these functions become packages.
“There should be one — and preferably only one — obvious way to do it.”
-The Zen of Python
This is not always the case, sometimes you have options, so many options. Feel free to explore them all. Before you do, make sure you have the first of these packages installed.
Here are 5 more packages you should know about:
Trying out a package the first time is a risk, it might not work, you might find something better. VirtualEnv creates an isolated environment where you can install and use packages without influencing the environment used for another project. Starting with a clean slate is as easy as setting up a new virtualenv. If you are serious about programming, this is the first package you need to install.
Python comes with a useful datetime module. When you need more power there is dateutil. Imagine having to parse dates in formats you do not control, like when you are trying to make sense of some scrapped information from dynamic source, the dateutil package will allow you to parse almost any string format to the generic date format. Need to calculate how long ago a twitter post was made? Dateutil easily calculates differences between date objects.
Python already have a relatively good REPL, which stands for “Read Evaluate Print Loop”. Basically this is where you get to run python commands in the terminal, and immediately see the effect. It is really helpful when exploring data, or some new code. I’ll let you try it out, most python tutorials starts you out in the REPL. bpython extends the functionality of the vanilla REPL to include syntax highlighting and expected parameter lists. The biggest help of the lot is the ability to Rewind. In the default REPL if you make a mistake in a loop it breaks, and you get to start from scratch. Rewind lets you “undo” some of the code you typed, and fix it.
Somewhere in your life as a developer you will crash into the need to do something with images. Maybe you want to resize images uploaded to a website so they fit specific dimensions. Maybe you are a bit more adventurous and want to apply funkey Instagram-esque filters for an image. You can even add watermarks to all images on your website like StockPhoto. Whenever you want to do work with images, start by importing pillow.
Decorators are functions that take other functions as arguments. Adding a decorator to a function allows you to change the input and output of the decorated function. In a simplistic use-case adding a decorator to a function that processes a dictionary can allow you to pass a raw JSON string to the function while the decorated function remains ignorant of the JSON and keeps processing the dictionary.
There you have it – 5 more python superpowers to add to your toolkit. Check out some of our previous python packages. Also, why not install virtualenv today and begin playing with some of these without messing with your main development environment?
Comment with your views on this article in the comments section below, and follow Hyperion Hub developments in the future if you’d like to see more articles like these for the South African market.