Add Python 2 support. Added filename extension as an argument.