Make gen_python.py Python 3 compatible

The gen_python.py script is modified to generate docs.py which can be used by both Python 2 and 3.

Currently, if the script is run by Python 3, the output is slightly different. Python 2 does not allow non-ascii characters to be printed in the repr() results, while Python 3 does not have such limitations.