문제

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

도움이 되었습니까?

해결책

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

data = json.dumps([columns for key, columns in crime.get_range()])
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top