Python-从文件中读取特定信息

Python-从文件中读取特定信息,python,Python,我需要做的是从我收到的文本文件中读取信息。其格式如下: <theme> <# of items>,<price>,<# of items>,<price> etc etc. <theme> <# of items>,<price>,<# of items>,<price> etc etc. <theme> <# of items>,<price&g

我需要做的是从我收到的文本文件中读取信息。其格式如下:

<theme>
<# of items>,<price>,<# of items>,<price> etc etc.
<theme>
<# of items>,<price>,<# of items>,<price> etc etc.
<theme>
<# of items>,<price>,<# of items>,<price> etc etc.
它还在继续

我知道如何打开文件进行阅读,这是最简单的部分。但我需要做的是读取主题名称,将它们设置为整数,将它们打印到屏幕上,让用户从中进行选择。我还需要能够从用户选择的主题下面的行中获取信息


有什么好方法可以做到这一点?

你自己可以试试吗?提示:使用字典,其中键是主题名称,值是给定主题属性的元组。有两种方法可以从这里开始。第一个是编写一个while-True:loop-ound-theme=f.readline;详细信息=f.readline;如果不是主题:休息。第二种方法是将该文件视为一个iterable,并查看如何将任何iterable分组成对,如果您自己无法理解,请查看itertools文档中的配方;然后你就可以在这些对上循环。