Error handling in Python3

In Python, you can handle errors with exceptions. The following code will generate an FileNotFound error because the file it is trying to open does not exist:

fh = open('data.txt')
for strline in fh.readlines():
    print(strline)

output

FileNotFoundError: [Errno 2] No such file or directory: 'data.txt'

An error is generated and the program stop executing. Suppose, we want to program to continue because we will compensate for this error later in the code. We can use try: except:

Object-Oriented Python3

Python is a fully object-oriented programming language but it can also be used for scripting. It is assumed that you are already familiar with object-orientation concepts and have experience writing object-oriented code in another language. This page will show how to write object-oriented code in Python without explaining object-oriented concepts.

The following class computes the area of a rectangle. Classes are defined with class keyword. init is the constructor. length and width are initialized in the constructor. Area is calculated by calcArea().

jQuery quick start

Before learning jQuery, you should learn HTML, CSS, JavaScript, and learn how to debug JavaScript. You should also be familiar with JSON. Knowing XML will also be helpful.

jQuery is a free and open source JavaScript library. It simplifies common web tasks such as state initialization or updating elements and makes it easy to make AJAX calls, manipulate content, and create animations. It also does the dirty work of dealing with cross-browser compatibility issues. jQuery's syntax is much simpler and concise than the syntax of vanilla JavaScript.

Working with Python and Excel

Note: The instructions are for python3.x on Ubuntu

There are several different libraries you can use to easily work with Excel. I will be covering openpyxl. Other options include xlsxwriter, xlrd, xlwt, and xltuils.

Installing openpyxl

To install openpyxl, make sure you have pip3 installed:

which pip3

If pip3 is not installed, install it first:

sudo apt-get install python3-pip

Once pip3 is installed:

Python3 for programmers

This publication is for programmers who want to learn python. It is assumed that you know what variable, arrays, data structures, functions, etc. already are. You only need python's syntax and tips for using them. So here, you will see more code and less explanation. If you are a programmer who only needs to fill in the blanks to become functional in python3, then you have come to the right place. If you need to learn programming, try googling "python for beginners". There are many excellent free online sources to learn python. You don't need to buy a book.

ArrayList and Iterator Example

This example shows how to use an iterator with ArrayList. Iterator can be used with other collections.

import java.util.*;

public class ArrayListIterator {
    public static void main(String[] args) {
        ArrayList al = new ArrayList();
        al.add(new Integer(11));
        al.add(new Integer(13));
        al.add(new Integer(17));

        Iterator itr = al.iterator();
        while (itr.hasNext()) {
            System.out.println(itr.next());
        }
    }
}

output

Pages