初学者需要编写一个查找、和打印的小程序,请python高手帮忙看看.
importosimporttypesimporttimeimportsysimportreimportstringreload(sys)sys.setdefaulten...
import os
import types
import time
import sys
import re
import string
reload(sys)
sys.setdefaultencoding('utf8')
QUIT_F = False
list1 = [];list2 = [];list3 = [];list4 = []
list5 = [];list6 = [];list7 = []
#定义存储类型为字典
formForEmployee = {"13408001234":list1,"13408000000":list2,\
"13547544512":list3,"13202220454":list4,"13808005454":list5,"18902112102":list6\
,"18900000000":list7}
print("\n")
def storage():
print(u"此手机通讯录有如下号码:")
print("------------------------------------\n")
print(u"【13408001234】\n【13408000000】\n【13547544512】\n【13202220454】\
\n【13808005454】\n【18902112102】\n【18900000000】\n")
print("------------------------------------")
def doall():
global formForEmployee
print(u"查询结果如下\n")
print(storage.formForEmployee.items())
raw_input()
def find():
global formForEmployee
storage()
#获取用户输入
name = str(raw_input("Please input number to find:"))
print("\n")
print(u"查找结果如下:\n")
#使用正则表达式函数进行模糊匹配并输出符合条件的数据
re0 = re.compile(name)
for name in storage.formForEmployee.items():
if re0.match(name[0]):
print(name)
raw_input()
def main():
while(not QUIT_F):
doall()或者find()
目前会报,对象属性错误,请高手帮忙看看。 展开
import types
import time
import sys
import re
import string
reload(sys)
sys.setdefaultencoding('utf8')
QUIT_F = False
list1 = [];list2 = [];list3 = [];list4 = []
list5 = [];list6 = [];list7 = []
#定义存储类型为字典
formForEmployee = {"13408001234":list1,"13408000000":list2,\
"13547544512":list3,"13202220454":list4,"13808005454":list5,"18902112102":list6\
,"18900000000":list7}
print("\n")
def storage():
print(u"此手机通讯录有如下号码:")
print("------------------------------------\n")
print(u"【13408001234】\n【13408000000】\n【13547544512】\n【13202220454】\
\n【13808005454】\n【18902112102】\n【18900000000】\n")
print("------------------------------------")
def doall():
global formForEmployee
print(u"查询结果如下\n")
print(storage.formForEmployee.items())
raw_input()
def find():
global formForEmployee
storage()
#获取用户输入
name = str(raw_input("Please input number to find:"))
print("\n")
print(u"查找结果如下:\n")
#使用正则表达式函数进行模糊匹配并输出符合条件的数据
re0 = re.compile(name)
for name in storage.formForEmployee.items():
if re0.match(name[0]):
print(name)
raw_input()
def main():
while(not QUIT_F):
doall()或者find()
目前会报,对象属性错误,请高手帮忙看看。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询