91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

python怎么用hook函數

養魚的貓咪
328
2021-03-08 17:30:50
欄目: 編程語言

python怎么用hook函數

在python中使用hook函數,具體方法如下:

import time

class LazyPerson(object):

def __init__(self, name):

self.name = name

self.watch_tv_func = None

self.have_dinner_func = None

def get_up(self):

print("%s get up at:%s" % (self.name, time.time()))

def go_to_sleep(self):

print("%s go to sleep at:%s" % (self.name, time.time()))

def register_tv_hook(self, watch_tv_func):

self.watch_tv_func = watch_tv_func

def register_dinner_hook(self, have_dinner_func):

self.have_dinner_func = have_dinner_func

def enjoy_a_lazy_day(self):

self.get_up()

time.sleep(3)

if self.watch_tv_func is not None:

self.watch_tv_func(self.name)

else:

print("no tv to watch")

time.sleep(3)

if self.have_dinner_func is not None:

self.have_dinner_func(self.name)

else:

print("nothing to eat at dinner")

time.sleep(3)

self.go_to_sleep()

def watch_daydayup(name):

print("%s : The program ---day day up--- is funny!!!" % name)

def watch_happyfamily(name):

print("%s : The program ---happy family--- is boring!!!" % name)

def eat_meat(name):

print("%s : The meat is nice!!!" % name)

def eat_hamburger(name):

print("%s : The hamburger is not so bad!!!" % name)

if __name__ == "__main__":

lazy_tom = LazyPerson("Tom")

lazy_jerry = LazyPerson("Jerry")

lazy_tom.register_tv_hook(watch_daydayup)

lazy_tom.register_dinner_hook(eat_meat)

lazy_jerry.register_tv_hook(watch_happyfamily)

lazy_jerry.register_dinner_hook(eat_hamburger)

lazy_tom.enjoy_a_lazy_day()

lazy_jerry.enjoy_a_lazy_day()

0
齐河县| 承德市| 石门县| 灵川县| 即墨市| 吴忠市| 靖州| 伊吾县| 天峨县| 贵港市| 枣阳市| 社会| 开阳县| 万州区| 神农架林区| 阿克陶县| 漳浦县| 疏勒县| 瓮安县| 吉首市| 松江区| 革吉县| 伊宁县| 安溪县| 伊川县| 姜堰市| 邵阳县| 大渡口区| 伊宁县| 武隆县| 常熟市| 庐江县| 太湖县| 手游| 东方市| 富宁县| 双辽市| 绍兴市| 巴林右旗| 阳江市| 元氏县|