python核心编程书中提到,由于类型与类的整合,一些内建函数变为了工厂函数,两者的关系是什么
被重新封装了,通过工厂函数来创建类的实例化,可以方便修改,对外函数不变,内部由于变化不影响使用
明显的例子: Timer 定时器的工厂函数
def Timer(*args, **kwargs):
"""Factory function to create a Timer object.
Timers call a function after a specified number of seconds:
t = Timer(30.0, f, args=[], kwargs={})
t.start()
t.cancel() # stop the timer's action if it's still waiting
"""
return _Timer(*args, **kwargs)