class Coon(object):
def __init__(self, host, password, port):
self.host = host
self.password = password
self.port = port
class CoonMysql(Coon):
def __init__(self, host, password, port, username, db, charset='utf-8'):
# Coon.__init__(self, host, password, port)调用父类的构造方法,自己手动调用父类的构造方法
super(CoonMysql, self).__init__(host, password, port) # 会自动找到父类,然后调用下面的方法
self.username = username
self.db = db
self.charset = charset
# 重写父类方法的目的是为了给他扩展一些功能
# 核心思想:先调用一下父类的方法,再写