Construct class dynamically to support both Python2 and Python3