Regular Expressions in Python Using The re Module

What is Regex?

Regex, or a more known terminology, Regular Expressions, is used to create complex patterns for searching substring inside Strings.

We have other methods of finding substring as well, but regex can cope up with way more complicated patterns than just normal searching for a substring.

How to Set Up Selenium With Python for Modern Web Automation

Selenium WebDriver is among one of the most popular tools when it comes to Web UI automation. The Selenium framework can be used with a wide range of programming languages such as Python, Java, C#, and more. As per the Stack Overflow Developer Survey, Python is the third-most loved programming language with 66.7%. It is also the most wanted programming language. So if you’re planning to perform test automation with Selenium and Python, you’re at the right place!

In this detailed Selenium Python tutorial, we would cover a range of topics such as the basics of Selenium WebDriver, Selenium WebDriver with Python, Selenium WebDriver vs. Selenium RC, and more.

Comparison of 11 New Python Web Frameworks

Python has been the go to language for building web services, right from quick-and-dirty RESTful APIs to full-fledged web applications that serve millions of users. If you have been dabbling in this area, you'd have probably used some of the most popular web frameworks already — Django, Flask, Falcon, Tornado, CherryPy, among others.

In the last few years, though, there have been many new kids on the block. These new frameworks have taken a fresh approach with a focus on the performance and expressiveness of the API. Here’s a comparison of new web frameworks in Python that you should consider for your next side project.

Selenium Python Tutorial: Getting Started With BDD In Behave

As technology becomes more complex, the number of people who actually understand it decreases. With Selenium test automation, the story is not so different, key stakeholders in a project, with the nontechnical background but with more insight into customer demand and use cases, might find it difficult to contribute to the process. 

Wouldn’t it be great, if the testers, developers, product managers, business managers, and other stakeholders in a project could sit under one roof to unearth new test cases, user stories and bugs for ensuring awesome product quality? 

How to Set Up a REST Service or a Web Application in Django

Introduction to Django and REST

Django is a very versatile framework, primarily used for developing web applications, but it is also widely used in creating mobile app backends and REST APIs, among other things. Here we will take a quick look at how to make these things possible using Django.

As you all probably know, REST stands for “Representational State Transfer.” Basically, what happens is that a user (or some software agent on one end) provides some input (or performs some activity) and the result of those inputs (or activities) are sent to the server side using a protocol that allows a request to be sent to the server (in most cases a HTTP protocol is used, but it doesn't need to be HTTP, as long as it can support a request/response scheme). The server, on receiving the request, makes appropriate changes to the state of the system (hence we call it “State Transfer”).

Python Tutorial for Beginners: Modules Related to DateTime

Python DateTime Modules

In this article, we will look at the Python DateTime module. We will learn how to create the current time, how to calculate a time gap, and how to produce time differences. According to the Python docs:

“The python DateTime module supplies classes for manipulating dates and times in both simple and complex ways.”

So, the Python DateTime modules contain several classes. Let us discuss them one by one.

Bulk Geocode Addresses Using Google Maps and GeoPy

Geocoding is the process of converting addresses (like a street address) into geographic coordinates (like latitude and longitude). With Woosmap you can request nearby location or display on a map a lot of geographic elements like stores or any other point of interest. To take advantages of these features, you first have to push geocoded locations to our system, as we discussed in this previous post. Most of the time, your dataset has addresses but no location information.

The following script, hosted on our Woosmap Github Organization, is a basic utility for geocoding CSV files that have address data included. It will parse the file and add coordinate information as well as some metadata on geocoded results like the location type, as discussed below. It calls the Geocoding API through the GeoPy Python client. 

Exporting Decision Trees in Textual Format With sklearn

In the past, we have covered Decision Trees showing how interpretable these models can be (see the tutorials here). In the previous tutorials, we exported the rules of the models using the function export_graphviz from sklearn and visualized the output of this function in a graphical way with an external tool which is not easy to install in some cases. Luckily, since version 0.21.2, scikit-learn offers the possibility to export Decision Trees in a textual format (I implemented this feature personally!) and in this post we will see an example how of to use this new feature.

Let's train a tree with two layers on the famous iris dataset using all the data and print the resulting rules using the brand new function export_text:

An Intro to StaticBox and StaticBoxSizers

There are many widgets that are included with the wxPython GUI toolkit. One of them is a fairly handy widget called wx.StaticBox. This widget accepts a string and then will draw a box with the string in the upper left-hand corner of the box. However, this only works when you use it in conjunction with wx.StaticBoxSizer.

Here is an example of what one might look like:

Using Python to Find Angles Where Graphs of Bessel Functions Cross

A previous post of mine looked at the angles that graphs make when they cross. For example, sin() and cos(x) always cross with the same angle. The same holds for sin() and cos(kx) since the k simply rescales the x-axis.

The post ended with wondering about functions analogous to sine and cosine, such as Bessel functions. This post will look at that question in more detail. Specifically we'll look at the functions Jν and Yν.

Tutorial on wxPython 4 and PubSub

The Publish-Subscribe pattern is pretty common in computer science and very useful too. The wxPython GUI toolkit has had an implementation of it for a very long time in wx.lib.pubsub. This implementation is based on the PyPubSub package. While you could always download PyPubSub and use it directly instead, it was nice to be able to just run wxPython without an additional dependency.

However, as of wxPython 4.0.4, wx.lib.pubsub is now deprecated and will be removed in a future version of wxPython. So now you will need to download PyPubSub or PyDispatcher if you want to use the Publish-Subscribe pattern easily in wxPython.

How to Use Python With Real-Time Data and REST APIs

1. Introduction

The Forex Quote API provided by 1forge.com is one of the most generous places with free plans to get real-time currency exchange values. The https://1forge.com/forex-data-api site includes an introduction to the Forex data API.

For free accounts, the REST rate limit is 1000 requests per day returning results in JSON format. It supports more than 700 currency pairs. Unfortunately, the Peruvian Sol (PEN) is not supported.

Automating Hadoop Computations on AWS

The Hadoop framework provides a lot of useful tools for big data projects. But it is too complex to manage it all by yourself. Several months ago, I was deploying a Hadoop cluster using Cloudera. And I discovered that it works well only for an architecture in which compute and storage capacity is constant. It is a nightmare to use a tool like Cloudera for a system that needs to scale. That is where cloud technologies come in and make our life easier. Amazon Web Services (AWS) is the best option for this use case. AWS provides a managed solution for Hadoop called Elastic Map Reduce (EMR). EMR allows developers to quickly start Hadoop clusters, do the necessary computations, and terminate them when all the work is done. To automate this process even further, AWS provides an SDK for EMR services. Using it, you can launch your Hadoop task with a single command. I'll show how it is done in an example below.

I am going to execute a Spark job on a Hadoop cluster in EMR. My goal will be to compute average comment length for each star rating (1-5) for a large dataset of customer reviews on amazon.com. Usually, to execute Hadoop computations, we need all the data to be stored in HDFS. But EMR integrates with S3 and we don’t need to launch data instances and copy large amounts of it for the sake of a two-minute computation. This compatibility with S3 is a big advantage of using EMR. Many datasets are distributed using S3, including the one I’m using in this example (you can find it here).

How to Write MatLab Functions in Python

Overview

Recently in my work, I was re-writing algorithms developed in MatLab to Python, some functions are not so simple to adapt, especially the array functions that are called Cell Arrays.

MatLab has an API where you can call MatLab functions via Python. The idea, however, was not to use MatLab, but the same algorithm works the same way using only Python and NumPy, and the GNU Octave also has an API similar to that of MatLab.