用户:
少年黑客神威查看:0 回复:0 评论:0 创建时间:2022-08-11T10:51:37
【作品展示】

【作品介绍】
一个小创意,献丑了(别忘了安装库——aiml)
最近我与6光星普爪稀尾想开一个工作室,不过室长没定,请大家支持一下我
【作品源代码】
import sys
import os
import warnings
try:
import aiml
except (AttributeError, ImportError):
print('''If you want to use english chat robot, please update lib aiml's Kernel.py
line 335 "start = time.time()" to:
"start = time.clock()"
and line 356 "print( "done (%.2f seconds)" % (time.clock() - start) )" to:
"print("done (%.2f seconds)" % (time.time() - start))"''')
warnings.warn('aiml module is wrong')
sys.exit(1)
def _get_module_dir(name):
if os.environ.get('show-info', False):
print('module', sys.modules[name])
path = getattr(sys.modules[name], '__file__', None)
if os.environ.get('show-info', False):
print(path)
if not path:
raise AttributeError('module %s has not attribute __file__' % name)
return os.path.dirname(os.path.abspath(path))
_alice_path = _get_module_dir('aiml') + '\\botdata\\alice'
os.chdir(_alice_path)
_alice = aiml.Kernel()
_alice.learn("startup.xml")
_alice.respond('LOAD ALICE')
def english_chat(message: str):
return _alice.respond(message)
if __name__ == '__main__':
while True:
msg = input('Please input, input q to quit: ')
if msg == 'q':
sys.exit(0)
print('Robot:', english_chat(msg))
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn