本文整理匯總了Python中weboob.tools.ordereddict.OrderedDict.iterkeys方法的典型用法代碼示例。如果您正苦於以下問題:Python OrderedDict.iterkeys方法的具體用法?Python OrderedDict.iterkeys怎麽用?Python OrderedDict.iterkeys使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類weboob.tools.ordereddict.OrderedDict
的用法示例。
在下文中一共展示了OrderedDict.iterkeys方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: format
# 需要導入模塊: from weboob.tools.ordereddict import OrderedDict [as 別名]
# 或者: from weboob.tools.ordereddict.OrderedDict import iterkeys [as 別名]
def format(self, obj, selected_fields=None, alias=None):
"""
Format an object to be human-readable.
An object has fields which can be selected.
:param obj: object to format
:type obj: BaseObject or dict
:param selected_fields: fields to display. If None, all fields are selected
:type selected_fields: tuple
:param alias: an alias to use instead of the object's ID
:type alias: unicode
"""
if isinstance(obj, BaseObject):
if selected_fields: # can be an empty list (nothing to do), or None (return all fields)
obj = obj.copy()
for name, value in obj.iter_fields():
if name not in selected_fields:
delattr(obj, name)
if self.MANDATORY_FIELDS:
missing_fields = set(self.MANDATORY_FIELDS) - set([name for name, value in obj.iter_fields()])
if missing_fields:
raise MandatoryFieldsNotFound(missing_fields)
formatted = self.format_obj(obj, alias)
else:
try:
obj = OrderedDict(obj)
except ValueError:
raise TypeError('Please give a BaseObject or a dict')
if selected_fields:
obj = obj.copy()
for name, value in obj.iteritems():
if name not in selected_fields:
obj.pop(name)
if self.MANDATORY_FIELDS:
missing_fields = set(self.MANDATORY_FIELDS) - set(obj.iterkeys())
if missing_fields:
raise MandatoryFieldsNotFound(missing_fields)
formatted = self.format_dict(obj)
if formatted:
self.output(formatted)
return formatted