Validating and Formatting Phone Numbers in Python with phonenumbers

Introduction Validating phone numbers can be a very challenging task. The format of a phone number can vary from one country to another. Heck, it can also vary within the same country! Some countries share the same country code, while some other countries use more than one country code. According to an example from the Google’s libphonenumber GitHub repository, USA, Canada, and Caribbean islands, all share the same country code (+1). On the other hand, it is possible to call […]

Read more

Test Driven Development with pytest

Introduction Good software is tested software. Testing our code can help us catch bugs or unwanted behavior. Test Driven Development (TDD) is a software development practice that requires us to incrementally write tests for features we want to add. It leverages automated testing suites, like pytest – a testing framework for Python programs. Automated Testing Developers usually write code, compile it if necessary, and then run the code to see if it works. This is an example of manual testing. […]

Read more

How to Exploit the Heartbleed Bug

First we explained how it worked, and now, thanks to Jared Stafford (and stbnps on Github for explanations) we can show you how to exploit it. Heartbleed is a simple bug, and therefore a simple bug to exploit. As you’ll see below, it only takes about a single page of Python to exploit this bug. Before we get to the code, here are a few reference links to help you understand the SSL protocol: The Code #!/usr/bin/python # Quick and […]

Read more

How to Send an Email with boto and SES

Introduction Pretty much every user-based app and website needs to send an email to the user at some point, so eventually you’ll have to deal with the joyous world of programmatic emailing. There are quite a few services popping up to help you with this, but with every app having its own unique requirements, few of these services adequately get the job done. So having faced the problem a few times (and in a few languages), I decided to write […]

Read more

Python async/await Tutorial

Asynchronous programming has been gaining a lot of traction in the past few years, and for good reason. Although it can be more difficult than the traditional linear style, it is also much more efficient. For example, instead of waiting for an HTTP request to finish before continuing execution, with Python async coroutines you can submit the request and do other work that’s waiting in a queue while waiting for the HTTP request to finish. It might take a bit […]

Read more

Install Python on Mac OSX

As with just about any open source software package, there are quite a few ways to install Python on Mac OSX. I figured it would be helpful to detail a few of the easiest ways to install Python, including the following: These are the most commons you’ll encounter, and each method has its own purpose, all of which I’ll detail in the sections below. Instructions for installing Python 2 and 3 are different in most cases (but not by much), […]

Read more

Python: Check if a File or Directory Exists

There are quite a few ways to solve a problem in programming, and this holds true especially in Python. Many times you’ll find that multiple built-in or standard modules serve essentially the same purpose, but with slightly varying functionality. Checking if a file or directory exists using Python is definitely one of those cases. Here are a few ways to check for existing files/directories and their nuances. Throughout these examples we’ll assume our current working directory has these files and […]

Read more

How to Send Emails with Gmail using Python

There are quite a few ways to send email with Python, whether it be through a 3rd party library like with boto and SES, or through an email protocol like SMTP. While the subject of using Python to send emails may seem like it’s been done to death, there are just so many different ways to do it and so many issues that can come up. I thought it would be helpful to write up a tutorial on how to […]

Read more

Reading and Writing JSON to a File in Python

Introduction In this article, we’ll be parsing, reading and writing JSON data to a file in Python. Over the last 5-10 years, the JSON format has been one of, if not the most, popular ways to serialize data. Especially in the web development world, you’ll likely encounter JSON through one of the many REST APIs, application configuration, or even simple data storage. Given its prevalence and impact on programming, at some point in your development you’ll likely want to learn […]

Read more

Reading and Writing CSV Files in Python

What is a CSV File? A CSV (Comma Separated Values) file is a file that uses a certain formatting for storing data. This file format organizes information, containing one record per line, with each field (column) separated by a delimiter. The delimiter most commonly used is usually a comma. This format is so common that it has actually been standardized in the RFC 4180. However, this standard isn’t always followed and there is a lack of universal standard usage. The […]

Read more
1 2