python 'type' object has no attribute '__getitem__'
python
import redis class Database: def __init__(self): self.host = 'localhost' self.port = '6379' self.db = '1' # self.password = '' def write(self, website,city,year,month,day,deal_number): try: key='_'.join([website,city,str(year),str(month),str(day)]) val=deal_number r=redis.StrictRedis(host=self.host, port=self.port) r.set(key, val) except Exception, exception: print exception def read(self, website, city, year, month, day): try: key='_'.join([website, city, str[year], str[month], str[day]]) r=redis.StrictRedis(host=self.host, port=self.port) value=r.get(key) print value return value except Exception, exception: print exception if __name__=='__main__': db=Database() db.write('meituan', 'beijing', 2015,7,26,8000) db.read('meituan', 'beijing', 2015,7,26)
但运行的结果见下,
'type' object has no attribute '
getitem
'
刚学Python,在连接redis出现了这个问题
求指点
毒岛的胸是我的
10 years, 3 months ago