Python Modules: Creating, Importing, and Sharing

Introduction Modules are the highest level organizational unit in Python. If you’re at least a little familiar with Python, you’ve probably not only used ready modules, but also created a few yourself. So what exactly is a module? Modules are units that store code and data, provide code-reuse to Python projects, and are also useful in partitioning the system’s namespaces in self-contained packages. They’re self-contained because you can only access a module’s attributes after importing it. You can also understand […]

Read more

Loops in Python

Choosing the Right Loop Construct Python offers a variety of constructs to do loops. This article presents them and gives advice on their specific usage. Furthermore, we will also have a look at the performance of each looping construct in your Python code. It might be surprising for you. Loops, Loops, Loops A programming language typically consists of several types of basic elements, such as assignments, statements, and loops. The idea behind a loop is to repeat single actions that […]

Read more

Reading and Writing XML Files in Python

XML, or Extensible Markup Language, is a markup-language that is commonly used to structure, store, and transfer data between systems. While not as common as it used to be, it is still used in services like RSS and SOAP, as well as for structuring files like Microsoft Office documents. With Python being a popular language for the web and data analysis, it’s likely you’ll need to read or write XML data at some point, in which case you’re in luck. […]

Read more

Understanding Python’s “yield” Keyword

The yield keyword in Python is used to create generators. A generator is a type of collection that produces items on-the-fly and can only be iterated once. By using generators you can improve your application’s performance and consume less memory as compared to normal collections, so it provides a nice boost in performance. In this article we’ll explain how to use the yield keyword in Python and what it does exactly. But first, let’s study the difference between a simple […]

Read more

Using Machine Learning to Predict the Weather: Part 3

This is the final article on using machine learning in Python to make predictions of the mean temperature based off of meteorological weather data retrieved from Weather Underground as described in part one of this series. The topic of this final article will be to build a neural network regressor using Google’s Open Source TensorFlow library. For a general introduction into TensorFlow, as well a discussion of installation methods, please see Mihajlo Pavloski’s excellent post TensorFlow Neural Network Tutorial. Topics […]

Read more

Formatting Strings with Python

Introduction Sooner or later string formatting becomes a necessary evil for most programmers. More so in the past before the thick client GUI era, but the need to have a specific string representation is still a common enough use case. My first introduction was back in college when I had an old-school prof that had a impure love for making us write Java console applications with neurotic specifications for outputting with the printf(…) function. One thing that held true then […]

Read more

Python zlib Library Tutorial

What is Python zlib The Python zlib library provides a Python interface to the zlib C library, which is a higher-level abstraction for the DEFLATE lossless compression algorithm. The data format used by the library is specified in the RFC 1950 to 1952, which is available at http://www.ietf.org/rfc/rfc1950.txt. The zlib compression format is free to use, and is not covered by any patent, so you can safely use it in commercial products as well. It is a lossless compression format […]

Read more

A SQLite Tutorial with Python

Introduction This tutorial will cover using SQLite in combination with Python’s sqlite3 interface. SQLite is a single file relational database bundled with most standard Python installs. SQLite is often the technology of choice for small applications, particularly those of embedded systems and devices like phones and tablets, smart appliances, and instruments. However, it is not uncommon to hear it being used for small to medium web and desktop applications. Creating a Database and Making a Connection Creating a new SQLite […]

Read more

Scheduling Jobs with python-crontab

What is Crontab Cron is a software utility that allows us to schedule tasks on Unix-like systems. The name is derived from the Greek word “Chronos”, which means “time”. The tasks in Cron are defined in a crontab, which is a text file containing the commands to be executed. The syntax used in a crontab is described below in this article. Python presents us with the crontab module to manage scheduled jobs via Cron. The functions available in it allow […]

Read more

K-Means Clustering with Scikit-Learn

Introduction K-means clustering is one of the most widely used unsupervised machine learning algorithms that forms clusters of data based on the similarity between data instances. For this particular algorithm to work, the number of clusters has to be defined beforehand. The K in the K-means refers to the number of clusters. The K-means algorithm starts by randomly choosing a centroid value for each cluster. After that the algorithm iteratively performs three steps: (i) Find the Euclidean distance between each […]

Read more
1 45 46 47 48 49 54