def monster(name):
with open('yvd.txt') as fd:
input=[x.strip('|').split('|') for x in fd.readlines()]
to_search={x[0]:x for x in input}
print('\n'.join(to_search[name]))
monster_name=input('Input monster to search: ')
monster(monster_name)
好的,所以我正在尝试monster
通过用户输入调用该函数。input
要求用户输入要搜索的怪物的名称。然后该函数monster
搜索输入的怪物并将其打印出来。但是我如何让它在函数中可以调用字符串呢?
输出示例:
Input monster to search: Boogie Man
Traceback (most recent call last):
File "C:\Users\Trevor\Desktop\yvd_read.py", line 8, in <module>
monster(monster_name)
TypeError: 'str' object is not callable
>>>