redis - python 'type' object has no attribute '__getitem__'
怪我咯
怪我咯 2017-04-17 15:31:03
[Python讨论组]
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出现了这个问题
求指点

怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复(2)
巴扎黑
str[year], str[month], str[day]
PHP中文网

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

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号