# -*- coding: utf-8 -*-
def yield_user_data(properties):
for property in properties:
value = yield property
def input_data(properties):
yud = yield_user_data(properties)
property = next(yud)
data = dict()
while property:
try:
value = raw_input('input {0} of data: '.format(property))
data[property] = value
property = yud.send(value)
except StopIteration as si:
break
return data
if __name__ == "__main__":
print 'data you inputed: {0}'.format(str(input_data(['name', 'age', 'sex', 'tel'])))
input name of data: zhangsan
input age of data: 22
input sex of data: M
input tel of data: 13566666666
data you inputed: {'age': '22', 'tel': '13566666666', 'name': 'zhangsan', 'sex': 'M'}
网友评论