因此,我正在製作一個Yu-Gi-Oh數據庫程序。我把所有的信息存儲在一個大的文本文件中。每個怪物chategorized通過以下方式:從Python中的文本文件獲取屬性
|Name|NUM 1|DESC 1|TYPE|LOCATION|STARS|ATK|DEF|DESCRIPTION
下面是一個實際的例子:
|A Feather of the Phoenix|37;29;18|FET;YSDS;CP03|Spell Card}Spell||||Discard 1 card. Select from your Graveyard and return it to the top of your Deck.|
所以我做了一個程序,按名稱搜索這個大的文本文件,並將其返回從文本文件中的信息沒有'|'。那就是:
with open('TEXT.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]))
現在我想修改我的計劃,所以我可以尋找怪物的名稱,並選擇哪個屬性我想顯示。所以它看起來像
A Feather of the Phoenix
Description:
Discard 1 card. Select from your Graveyard and return it to the top of your Deck.
任何線索,我怎麼能做到這一點?
這是完美的!感謝您的幫助。 – user1985351