Python:从txt文件中提取的列表为无法识别为列表的字符串

问题描述 投票:1回答:1

我将epguide API中的表演数据保存在一个txt文件中,如下所示:

[{{epguide_name':'gooddoctor','title':'The Good Doctor','imdb_id':'tt6470478','episodes':'http://epguides.frecar.no/show/gooddoctor/','first_episode':'http://epguides.frecar.no/show/gooddoctor/first/', 'next_episode':'http://epguides.frecar.no/show/gooddoctor/next/','last_episode':'http://epguides.frecar.no/show/gooddoctor/last/','epguides_url':'http://www.epguides.com/gooddoctor'}]

[当我现在尝试将其作为python中的列表读取时,尽管有方括号,但它不能识别为字符串,而只能识别为字符串:

    with open(file_shows, 'r', encoding='utf-8') as fs:
       fs = fs.read()
       print(type(fs))
       print(next((item for item in list if item['title'] == show), None)['episodes'])

类型仍然是str,因此搜索也无法正常工作。如何将数据“返回”转换为列表?

我从epguide API中将表演数据保存在一个txt文件中,该文件如下所示:[{'epguide_name':'gooddoctor','title':'Good Doctor','imdb_id':'tt6470478','情节”:“ http:// epguides ....

python string list square-bracket
1个回答
0
投票

一种解决方法如下,

© www.soinside.com 2019 - 2024. All rights reserved.