本文整理汇总了Python中error.Error.data_error方法的典型用法代码示例。如果您正苦于以下问题:Python Error.data_error方法的具体用法?Python Error.data_error怎么用?Python Error.data_error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类error.Error
的用法示例。
在下文中一共展示了Error.data_error方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sort_into_dictionary
# 需要导入模块: from error import Error [as 别名]
# 或者: from error.Error import data_error [as 别名]
def sort_into_dictionary(wedding_list, guest_list):
'''sort_into_dictionary(str, dictionary_object)
Takes a grouping of strings and sorts them into
a python dictionary object. A python dictionary object is implemented
using a hash function. This makes anything involving look up extremly
fast. Much faster then using a list object.
'''
error = Error()
wedding_list = wedding_list.split(",")
for guest in wedding_list:
# ensure that the name before the dash is not empty
try:
name = guest.split("-")[0].strip().title()
response = guest.split("-")[1].strip("\n").lower()
except IndexError:
error.data_error()
else:
# check that responses in rsvp file is not empty
if not response or not name:
error.data_error()
# adds the names and replies to the dictionary object. If the name
# already exists meaning that there is another guest with same name
# append their reply to that name
if name not in guest_list.keys() :
guest_list[name] = [response]
else:
guest_list[name].append(response)