本文整理汇总了Python中bigml.fields.Fields.keys方法的典型用法代码示例。如果您正苦于以下问题:Python Fields.keys方法的具体用法?Python Fields.keys怎么用?Python Fields.keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bigml.fields.Fields
的用法示例。
在下文中一共展示了Fields.keys方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_fields_changes
# 需要导入模块: from bigml.fields import Fields [as 别名]
# 或者: from bigml.fields.Fields import keys [as 别名]
def get_fields_changes(resource, referrer=None,
updatable_attrs=DEFAULT_UPDATABLE):
"""Changed field attributes
"""
if referrer is None:
referrer = {}
fields_attributes = {}
resource_fields = Fields(
{'resource': resource['resource'], 'object': resource}).fields
resource_type = get_resource_type(resource)
# for sources, extract all the updatable attributes
if resource_type == 'source':
updatable_attrs = SOURCE_UPDATABLE
for field_id in resource_fields.keys():
field_opts = {}
field = resource_fields[field_id]
for attribute in updatable_attrs:
if field.get(attribute):
field_opts.update({attribute: field[attribute]})
if field_opts != {}:
fields_attributes.update({field_id: field_opts})
return fields_attributes
# for the rest of resources, check which attributes changed
if referrer:
referrer_fields = Fields(
{'resource': referrer['resource'], 'object': referrer}).fields
for field_id in resource_fields.keys():
field_opts = {}
if not field_id in referrer_fields.keys():
continue
field = resource_fields[field_id]
for attribute in updatable_attrs:
ref_values = ["", referrer_fields[field_id].get(attribute, "")]
if not field.get(attribute, "") in ref_values:
field_opts.update({attribute: field[attribute]})
if field_opts != {}:
fields_attributes.update({field_id: field_opts})
return fields_attributes