假期苦短,我用Python!这有个自动回复拜年信息的小程序( 六 )

代码

创建Python文件比如 newYear.py 代码内容如下:

\"\"\"newYear.py test\"\"\"# coding: utf-8import itchat refrom itchat.content import *import randomimport jsonimport codecs\"\"\"    Constants\"\"\"#REPLY = {'default': '祝您猪年大吉'REPLY = {'default': ''try:    with open(\"REPLY.json\" 'r' encoding='utf-8') as load_f:        json_str = load_f.read()        print(json_str)        if json_str:            if json_str.startswith(u'\\ufeff'):                json_str = json_str.encode('utf8')[3:
.decode('utf8')            REPLY = json.loads(json_str)except Exception as e:    print(e)print(\"replies:\" REPLY)@itchat.msg_register([TEXT
)def text_reply(msg):    items = REPLY.items()    defFlag = True    for key alue in items:        #print(key \"\" alue)        match = re.search(key msg['Text'

推荐阅读