新手python 连接redis问题,pythonredis,pythonimport


pythonimport redisclass 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 exceptionif __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出现了这个问题
求指点

我的是把f(i)写成了f[i],所以类型(Type)no attribute了。反正初学就这样,很蛋疼

str[year], str[month], str[day]

编橙之家文章,

评论关闭