Database Reference
In-Depth Information
'AMZN', "
" 297.92, -0.94, -0.31);")
Reading Data
When reading data, the query execution will return an iterable set of results that
will allow access to the values of the fields requested. Listing 9.20 shows query
execution and printing the results to the console.
Listing 9.20 Reading Data in Python
Click here to view code image
def print_results(self):
results = self.session.execute("SELECT * FROM
portfolio_demo.portfolio "
"WHERE portfo-
lio_id = "
"756716f7-2e54-4715-9f00-91dcbea6cf50;")
print "%-7s\t%-7s\t%-7s\t%-7s\n%s" % \
("Ticker", "Price", "Change", "PCT",
"........+........+........+........")
for row in results:
print "%-7s\t%0.2f\t%0.2f\t%0.2f" % \
(row.ticker, row.current_price,
row.current_change,
row.current_change_percent)
Putting It All Together
Listing 9.21 shows the entire sample class as it would look in an application.
Listing 9.21 Full Python Sample
Click here to view code image
from cassandra.cluster import Cluster
class SampleApp(object):
 
 
Search WWH ::




Custom Search