标签:mem 字符串 格式 lib 取出 下载 family open imp
1 import xlrd 2 class ExcelHandleImpl(object): 3 ‘‘‘ 4 classdocs 5 ‘‘‘ 6 7 def __init__(self): 8 ‘‘‘ 9 Constructor 10 ‘‘‘ 11 self.filename = None 12 #打开excel 13 def open_excel(self,filename): 14 try: 15 data = xlrd.open_workbook(filename) 16 return data 17 except Exception,e: 18 print str(e) 19 #根据sheet名字获取信息 20 def excel_table_byname(self,filename,colnameindex=0,by_name=u‘merchant‘): 21 # 实例化类 22 bswi = ExcelHandleImpl() 23 data = bswi.open_excel(filename) 24 table = data.sheet_by_name(by_name) 25 #得到表格行数 26 nrows = table.nrows 27 #得到第一行的数据 28 colnames = table.row_values(colnameindex) 29 print colnames 30 list = [] 31 for rownum in range(1,nrows): 32 row = table.row_values(rownum) 33 if row: 34 app = {} 35 #组成字典 36 for i in range(len(colnames)): 37 app[colnames[i]] = row[i] 38 list.append(app) 39 return list
1 excel = ExcelHandleImpl() 2 tables = excel.excel_table_byname(‘C:\Users\BG302224\Desktop\datasetup.xlsx‘,0,‘goods‘)
excel = ExcelHandleImpl() tables = excel.excel_table_byname(‘C:\Users\BG302224\Desktop\datasetup.xlsx‘) for row in tables: print row row = json.dumps(row)
row = {"message":row}
row[‘merchantstatus‘] = eval(row[‘merchantstatus‘])
row[‘alipayaccount‘] = ‘‘
row[‘merchantstatus‘] = eval(row[‘merchantstatus‘])
e.要是请求参数是以这种方式的:id:“1234”,name:“三生三世十里桃花”
是将冒号后面的字符串序列 话
id = "1234" name = "0001" data = {"id":json.dumps(id),"name":json.dumps(name)}
要是有更好的建议可以告诉我!!!!
标签:mem 字符串 格式 lib 取出 下载 family open imp
原文地址:http://www.cnblogs.com/AI-xigua/p/7359903.html