1. CSV Reader and Writer
import csv
class CsvReader():
def __init__(self,filename):
#self.reader = csv.reader(open(filename, 'rb'), delimiter=',', quotechar='"')
self.reader = csv.reader(open(filename, 'rb'))
def dump(self):
for row in self.reader:
print(row)
class CsvWriter():
def __init__(self,filename):
self.writer = csv.writer(open(filename, 'wb'))
def writerow(self,row):
self.writer.writerow(row)
if __name__ == "__main__":
r = CsvReader('a.csv')
r.dump()
w = CsvWriter('b.csv')
w.writerow(['Spam'] * 5 + ['Baked Beans'])
w.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])
댓글 없음:
댓글 쓰기