Python code to find the md5 checksum of a file

Checksum calculation is an unavoidable and very important step in places where we transfer files/data. The simplest way to ensure whether a file reached the destination properly or not is by comparing the checksum of source and target files. Checksum can be calculated in several ways. One is by calculating the checksum by keeping the entire file as a single block. Another way is multipart checksum calculation, where we calculate the checksum of multiple small chunks in the file and finally calculating the aggregated checksum.
Here I am explaining about the calculation of checksum of a file using the simplest way. I am using the hashlib library in python for calculating the checksum.
Suppose I have a zip file located in the location /home/coder/ The checksum of the file can be calculated as follows.

import hashlib
file_name = ‘/home/amal/’
checksum = hashlib.md5(open(file_name).read()).hexdigest()
print checksum

One common mistake I have seen among people is passing the file name directly without opening the file

Eg: hashlib.md5(file_name).hexdigest()

This will also return a checksum. But it will be calculating the checksum of the file name, not the checksum calculated based on the contents of the file. So always use the checksum calculation as follows


This will return the exact checksum.

In linux, you can calculate the md5sum using a commandline utility also.

> md5sum file_name

Swapping Two numbers without using a third variable

This is a simple method for swapping the values of two numeric variables without using a third variable.
The sample java code is given below.

public void Swapping(int a, int b)
                System.out.println(Values Before Swapping);
		System.out.println(a+" , "+b);
                System.out.println(Values After Swapping);
		System.out.println(a+" , "+b);

Checking for Odd or Even without using any Conditional Statements

Last day my friend asked me a question to write a program which tells whether a given number is odd or even without using any conditional statements. It is very simple. There may be several solutions. Two of the solutions are given below. The code is given below

Using Array

public void OddEven(int num)
		String []store = {"even","odd"};
		System.out.println("The number is "+store[(num%2)]);	

Using try-catch

public void EvenOdd ( int num)
		int temp = num%2;
		try {
			int ans = 10/temp;
			System.out.println("Number is odd");
		catch (Exception e) {
			System.out.println("Number is Even");

BigDataEdge got shortlisted in the V3 Technology Awards 2013

V3 has announced its Technology Awards 2013 shortlist. Infosys BigDataEdge got nominated as one among the best three bigdata products in the world.
I am working in this BigDataEdge team. Feeling very much happy ..:)

Visit the below website for more details.

Infosys BigDataEdge