CSV Writer in Python
Real time data feeds are so pervasive in all walks of our lives.
Every day our smart phones deal with lot of real time data feeds like
Weather Feeds, Traffic Updates, Stock Quotes and so on. CSV is the most common format used for Dissemination as well as storage of these real time data.
In Python the CSV Writer class of csv module provides an implementation of CSV writing logic and makes developers life lot easier.
Python CSV Writer Example
import csv
with open('./quotes.csv', 'w', newline='') as QuotesFile: quote1 = ["MSFT", "62.30", "62.48", "63.41", "62.12", "487.83", "29.79", "2.50"] CSVWriter = csv.writer(QuotesFile, delimiter=',',quotechar='"') CSVWriter.writerow(quote1)
# Write Next quote # The quote for MSFT changes every fraction of a second quote2 = ["MSFT", "62.28", "62.48", "63.41", "62.12", "487.83", "29.79", "2.50"] CSVWriter.writerow(quote2)
|
Python CSV Writer Output:
MSFT,62.30,62.48,63.41,62.12,487.83,29.79,2.50 MSFT,62.28,62.48,63.41,62.12,487.83,29.79,2.50
|