python2的兼容性

StringIO

python3
from io import StringIO

python2
from io import BytesIO as StringIO

父类和子类

python3

class BaseClass:

    def init(self):
        ...

class DeriveClass:

    def init(self):
        super().init()

python2

class BaseClass(object):

    def init(self):
        ...

class DeriveClass:

    def init(self):
        super(DeriveClass, self).init()

判断python3还是python2

import sys

def is_python_3():
    return sys.version_info.major >= 3