新手python 连接redis问题,pythonredis,pythonimport
新手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]
编橙之家文章,
相关内容
- Flask小程序Dockerfile找不到目标问题,flaskdockerfile,这是我
- Python Requests爬取目标网页代码,求神帮看下源码,pyt
- Python win32打开文件夹函数调用操作问题,pythonwin32,假如
- Django配置mysql数据库使用问题,djangomysql,django配置好m
- Python递归找到目标后停止递归方法是什么,python递归
- 请教Python切片分割及插入问题,,n = [1,5]n[1
- 求适合阅读c/c++/python的web服务器代码,pythonweb,比如ng
- 想知道Python爬虫程序原理,Python爬虫程序原理,python爬虫
- python连接kafka集群保证broker不可用时正常发送,kafkabr
- python删除字符串str中指定位置字符,pythonstr,原程序是这
评论关闭