# I have the dictionary my_dict
my_dict = {
'var1' : 5
'var2' : 9
}
r = redis.StrictRedis()
Run Code Online (Sandbox Code Playgroud)
我如何存储my_dict并使用redis检索它.例如,以下代码不起作用.
#Code that doesn't work
r.set('this_dict', my_dict) # to store my_dict in this_dict
r.get('this_dict') # to retrieve my_dict
Run Code Online (Sandbox Code Playgroud) 我无法理解它.我想将字典的值插入到sqlite数据库中.
url = "https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=5f...1b&per_page=250&accuracy=1&has_geo=1&extras=geo,tags,views,description"
soup = BeautifulSoup(urlopen(url)) #soup it up
for data in soup.find_all('photo'): #parsing the data
dict = { #filter the data, find_all creats dictionary KEY:VALUE
"id_p": data.get('id'),
"title_p": data.get('title'),
"tags_p": data.get('tags'),
"latitude_p": data.get('latitude'),
"longitude_p": data.get('longitude'),
}
#print (dict)
connector.execute("insert into DATAGERMANY values (?,?,?,?,?)", );
connector.commit()
connector.close
Run Code Online (Sandbox Code Playgroud)
我的键id_p,title_p等和值我检索通过data.get.
但是,我无法插入它们.当我试着写id, title, tags, latitude, longitude在后面...DATAGERMANY values (?,?,?,?,?)", );我得到
NameError: name 'title' is not defined.
我尝试了dict.values,dict但随后它的说法table …