[英]Python Append JSON list within for loop
I have the following Python code which takes data from cassandra database. 我有以下Python代码从cassandra数据库获取数据。 What i want to achieve is to have json encoded variable at the end.
我想要实现的是在最后使用json编码变量。 However, not surprisingly, my code only attaches the latest data row to the variable.
但是,毫不奇怪,我的代码只将最新的数据行附加到变量。
How can I combine or append all of the data to a single variable? 如何将所有数据组合或附加到单个变量?
for key, columns in crime.get_range():
data = json.dumps(columns)
Thanks 谢谢
I am using Pycassa as a library to access Cassandra 我使用Pycassa作为访问Cassandra的库
首先收集列表中的所有数据,然后编码该列表:
data = json.dumps([columns for key, columns in crime.get_range()])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.