python---简单数据库

#simple database

#people
people = {
	'Alice':{
		'phone':'2341',
		'addr':'Foo drive 23'
	},
	'Beth':{
		'phone':'9102',
		'addr':'Bar street 42'
	},
	'Ceil':{
		'phone':'3158',
		'addr':'Baz avenue 90'
	}
}

#describe
labels = {
	'phone':'phone number',
	'addr':'address'
}

name = raw_input('Name:')

request = raw_input('Phone number (p) or adress (a)?')

#find phone or address
if request == 'p':key = 'phone'
if request == 'a':key = 'address'

if name in people: print "%s's %s is %s." % (name,labels[key],people[name][key])
简单的数据库

 python version 2.4.3

你可能感兴趣的:(python---简单数据库)