python 'type' object has no attribute '__getitem__'

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

阅读 13.8k
2 个回答
str[year], str[month], str[day]
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题