class GetExpense: __dc__ = 'require a mouser partnumber and count, return the expense' def __init__(self,req_mmp,req_count): self.mmp = req_mmp self.count = req_count# '56' def get_expense(self): self.shili = GetDataFromMouser(self.mmp) self.str_pagestring = self.shili.getstring_mmp() if self.str_pagestring == '': dict = {} dict['error'] = '根据你输入的mouser型号,在mouser.com无法找到你需要的信息' return dict else: if check(self.count) != True: dict = {} dict['error'] = '你输入的数量中包含只能够包含 0-9 这10个数字,请重新输入数量' return dict else: self.count = int(self.count)# '100' to 100 self.dict_pric = self.shili.getinfo_pric(self.str_pagestring) pop(self.dict_pric)#{1:'$0.32',10:'0.30',100:'$0.28'} list_quan = self.dict_pric.keys() list_quan.sort()#[1,10,100,1000] self.dict_avai = self.shili.getinfo_avai(self.str_pagestring) stock = self.dict_avai['Stock'].replace(',','') getcount = re.findall('(\d{1,10})',stock,flags=16) if getcount ==[] or getcount == ['0']: self.stock_count = 0 else : self.stock_count = int(getcount[0]) expense = return_exp(list_quan,self.dict_pric,self.count,self.stock_count,self.mmp) return expense