I want to read a csv file from STDIN and operate on it.
The following is the code for reading the csv file and doing the operation needed. This works fine. But I want to take the input from STDIN.
import csv
with open('hospital_data.csv', 'rb') as csvfile:
myDict = {}
csvreader = csv.reader(csvfile, delimiter=',')
for row in csvreader:
if row[6] not in myDict.keys():
#print 'Zipcode: ' + row[6] + ' Hospital code: ' + row[1]
myDict[row[6]] = 1
elif row[6] in myDict.keys():
#print 'value in row '+ str(myDict[row[6]])
myDict[row[6]] += 1
Is there a way in Python to read the file from STDIN as a csv file ?