如何访问此列表中的数据?

时间:2018-10-10 16:21:05

标签: python imdb imdbpy

我正在使用IMDBpy来获取使用此功能的任何电视连续剧的发行日期。

  services
            .AddMvc(options =>
                {
                    var L = services.BuildServiceProvider().GetService<IStringLocalizer>();
                    options.ModelBindingMessageProvider.SetValueIsInvalidAccessor(
                        (x) => L["The value '{0}' is invalid."]);
                    options.ModelBindingMessageProvider.SetValueMustBeANumberAccessor(
                        (x) => L["The field {0} must be a number."]);
                    options.ModelBindingMessageProvider.SetMissingBindRequiredValueAccessor(
                        (x) => L["A value for the '{0}' property was not provided.", x]);
                    options.ModelBindingMessageProvider.SetAttemptedValueIsInvalidAccessor(
                        (x, y) => L["The value '{0}' is not valid for {1}.", x, y]);
                    options.ModelBindingMessageProvider.SetMissingKeyOrValueAccessor(
                        () => L["A value is required."]);
                    options.ModelBindingMessageProvider.SetUnknownValueIsInvalidAccessor(
                        (x) => L["The supplied value is invalid for {0}.", x]);
                    options.ModelBindingMessageProvider.SetValueMustNotBeNullAccessor(
                        (x) => L["Null value is invalid.", x]);
                })
            .AddViewLocalization()
            .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver())
              .AddDataAnnotationsLocalization(options => {
                  options.DataAnnotationLocalizerProvider = (type, factory) =>
                  {
                      return  services.BuildServiceProvider().GetService<IStringLocalizer>();
                  };
              })
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddTransient<IStringLocalizer, Services.XMLStringLocalizerService>();

现在此函数返回此值-

episode_Release_date = ia.get_movie_release_dates(episode_id)

现在我只想要与美国有关的数据。如何在此列表中访问美国的发行日期。

API函数-

{'data': {'raw release dates': [{'country': 'Argentina', 'date': '30 July 2017'}, {'country': 'USA', 'date': '30 July 2017'}, {'country': 'Germany', 'date': '31 July 2017', 'notes': ' (limited)'}, {'country': 'UK', 'date': '31 July 2017'}, {'country': 'Italy', 'date': '31 July 2017'}], 'release dates': ['Argentina::30 July 2017', 'USA::30 July 2017', 'Germany::31 July 2017 (limited)', 'UK::31 July 2017', 'Italy::31 July 2017']}, 'titlesRefs': {}, 'namesRefs': {}, 'info sets': ('release dates', 'akas')}

我是python的新手,只是一个初学者。

2 个答案:

答案 0 :(得分:1)

在浏览嵌套词典时,使用$SOURCES = src/century/century_carbon.cpp ... src/for_branching.cpp ... src/grass/grass_log.cpp ... $OBJECTS = build/century_carbon.o ... build/for_branching.o ... build/grass_log.o ... 有助于可视化

pprint

答案 1 :(得分:1)

看起来返回值是一个json字符串,但是我不确定为什么返回值中会出现“(”,“)”。假设这是一个正确的json值,则可以使用json模块解析并获取所需的值。

如果您要搜索原始发布日期-

for relEntry in episode_Release_date['data']['raw release dates']:
    if relEntry['country'] == "USA":
        print(relEntry) 

如果您要搜索发行日期-

for relEntry in episode_Release_date['data']['release dates']:
    if "USA" in relEntry:
        print(relEntry)