update database.py to be compatible with python 2 and 3