我从 API 获取数据并保存到名为 data[] 的列表中。在此之后,我将这些数据发送到另一个类以对其进行格式化。我想创建一个字典,所以我可以保存这些数据。我正在尝试做这样的事情:import jsonimport datetime class MovieFormatter(): def format(self, data): data = { "movie_info_name": data['title'] "movie_info_duration": data['duration'] "movie_info_description": data['synopsis'] "movie_info_genres": data['genres'] "movie_info_actor": data['cast'] "movie_info_director": data['director'] data['trailers'] = data.get('trailers') or [] "dictionary": [{'url': x['url'], 'type': x['type']} for x in data['images'] + data['trailers']] } return data这是正确的做法吗?
添加回答
举报
0/150
提交
取消