Question

I have the following Python code which takes data from cassandra database. What i want to achieve is to have json encoded variable at the end. 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

Était-ce utile?

La solution

Collect all the data in a list first, then encode that list:

data = json.dumps([columns for key, columns in crime.get_range()])
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top