db = UnQLite('test.db')
data = db.collection('data')
print(data.fetch(0))
此打印
{'id': b'abc', 'type': b'business', 'state': b'AZ', 'latitude': 33.3482589,
'name': b"ABC Restaurant", 'full_address': b'1835 E ABC Rd, Ste C109, Phoenix, AZ 85284',
'categories': [b'Restaurants', b'Buffets', b'Italian'],
'open': True, 'stars': 4, 'city': b'Phoenix', 'neighborhoods': [],
'__id': 0, 'review_count': 122, 'longitude': -111.9088346}
如何获取City的“凤凰”值?
type(data.fetch(0))
打印类'dict'
我正在查看UnQlite文档,但发现不多。请帮忙。
您已经有了字典,因此只需要搜索密钥
x = {'id': b'abc', 'type': b'business', 'state': b'AZ', 'latitude': 33.3482589,
'name': b"ABC Restaurant", 'full_address': b'1835 E ABC Rd, Ste C109, Phoenix, AZ 85284',
'categories': [b'Restaurants', b'Buffets', b'Italian'],
'open': True, 'stars': 4, 'city': b'Phoenix', 'neighborhoods': [],
'__id': 0, 'review_count': 122, 'longitude': -111.9088346}
x['city']
#b'Phoenix'
这Phoenix
不是str
对象,byte
所以如果您希望将其作为字符串,则可以使用decode
x['city'].decode()
#'Phoenix'
或您的情况:
data.fetch(0)['city'].decode()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句