Proper Cleanup of Resources in Python using the With Statement

The python with statement is damn useful! Learn the intricacies of the with statement.

“Accept who you are. Unless you’re a serial killer.” ― Ellen DeGeneres, Seriously… I’m Kidding

1. Introduction

Resource acquisition and cleanup is a very crucial aspect of programs. Resources need to be properly cleaned and released as soon as their usage is complete. Failing which scare resources might not be available to other programs running on the same machine. This is especially true for long-running programs such as servers and daemons.

Continue reading “Proper Cleanup of Resources in Python using the With Statement”

Python Class Methods – Implementing Ordered Dictionary

Use python class special methods to add idiomatic behavior to your class.

“It is the time you have wasted for your rose that makes your rose so important.” ― Antoine de Saint-Exupéry, The Little Prince

1. Introduction

The python class system supports a number of special methods which allows class implementations to mimic built-in python objects objects. These special methods are invoked by the python run-time system in a way similar to the built-in classes. For example, the method __len__() can be defined by a user class which will be invoked when the client code attempts to find the length of the object using len(obj).

Continue reading “Python Class Methods – Implementing Ordered Dictionary”

Nested or Inner Classes in Python

Learn how to declare and use nested classes in python

“There is nothing either good or bad, but thinking makes it so.” ― William Shakespeare, Hamlet

1. Introduction

A nested or inner class is contained within another class. This could be for reasons of encapsulation, where the inner class is not useful by itself. Continue reading “Nested or Inner Classes in Python”

An Introduction to Python Classes

Here is a beginner’s introduction to classes in python

“Sometimes it’s worth lingering on the journey for a while before getting to the destination.” ― Richelle Mead, The Indigo Spell

1. Introduction

The concept of a class is the core of Object Oriented Programming. It defines a blue-print for constructing objects. It is a plan of how an object is laid out, including its data members, instance methods, class methods and inheritance hierarchy. Python supports object oriented programming and classes, although with certain differences from other languages like C++ and Java. In this article, we shall delve into python classes and learn how they work.

Continue reading “An Introduction to Python Classes”

What is the Python Yield Statement?

Learn about the Python yield statement which is used to create generators.

“Count your age by friends, not years. Count your life by smiles, not tears.”
― John Lennon

1. Introduction

Python provides an yield statement which allows you to create generator functions. What is a generator function and how does the yield statement help with it? Let us find out in this article.

Continue reading “What is the Python Yield Statement?”

An Introduction to Python Sets

Python supports sets which are a collection of unique elements and provide operations for computing set union, intersection and difference.

“The world is a book and those who do not travel read only one page.”
― Augustine of Hippo

1. Introduction

A set is a collection of unique elements. A common use is to eliminate duplicate elements from a list. In addition, it supports set operations like union intersection and difference.

Continue reading “An Introduction to Python Sets”

Getting Started with Scrapy

Learn how to use Python Scrapy to Extract information from Websites.

“When life gives you lemons, chunk it right back.”
― Bill Watterson

1. Introduction

Scrapy is a python-based web crawler which can be used to extract information from websites. It is fast, simple and can navigate pages just like a browser can.

Continue reading “Getting Started with Scrapy”

Listing a Directory With Python

Learn how to list contents of a directory from python. Also, easily find and process files matching conditions from your python program.

“If at first you don’t succeed, destroy all evidence that you tried.”
― Steven Wright

1. Introduction

There are several methods to list a directory in python. In this article we present a few of these along with the caveats for each.

Continue reading “Listing a Directory With Python”

Pandas Tutorial – Using Matplotlib

Learn how to massage data using pandas DataFrame and plot the result using matplotlib in this beginner tutorial.

“There is only one thing that makes a dream impossible to achieve: the fear of failure.”
― Paulo Coelho, The Alchemist

1. Introduction

Matplotlib is a graphics and charting library for python. Once data is sliced and diced using pandas, you can use matplotlib for visualization. In this starter tutorial, we take you through the steps to do just that.

Continue reading “Pandas Tutorial – Using Matplotlib”