This article aims to provide a somewhat gentle introduction to python generator, and hopefully will inspire the reader to find interesting uses for them. It is a somewhat complicated topic with a lot of small details, so we will use the convention below to provide extra information. Feel free to skip over these, as they… Continue reading
In this article I will introduce you to exception handling. In the previous articles in this series we use exception handling to cover some rare exception cases (remember the Guess the Number game?) and now it is time to explain how to do it in your own application — and when to do it.
Python is available for various platforms which includes Linux, Windows and Mac OS. So here we are going to understand how to setup python environment. For the local environment setup open the terminal window and type there “python” to know that it is already installed or not, if installed then which version.
As in Python it is not necessary to create our code into classes while developing program as we can use functions also which is known as Procedural Programming. However, a procedural programming is used for writing small, short and simple programs whereas object oriented programming (OOP) programs becomes more important as the programs grows in… Continue reading
Comparing dates (or datetime objects) in Python is very easy. The basic comparison operators (==, !=, <>, >, <, >=, <=) are overloaded for the datetime object, so comparing dates is very intuitive and quick.
Sometimes we have to work with dates and times. I use dates less than times because with times you can measure code execution time which is sometimes essential (for my website scraping book’s performance measurement is the core part I guess).
Now we arrived at object-oriented programming. This has (had) its hype where every language was designed around objects and Python developer Guido van Rossum thought “Why not?” and added classes to support object-oriented development. Some python evangelists think this was a bad decision, some think it was a good approach…
We have seen this example previously. There I included a lot of loops to handle user input and the main logic… Now it is time to refactor the application to use functions. This should make the code readable and we could re-use parts later.
Now we have learned the basics of Python programming: variables, collections and loops. If you have followed the examples and the tutorial you might feel that sometimes we use too much code and it can be leveraged a bit. But maybe you do not know how to do it. Most of the time the solution… Continue reading
Now let’s write a script which implements a basic “Guess the number” game. The rules of the game are: