# -*- coding: utf-8 -*-
import os
import csv
data_dir = 'some_dir'
input_file = os .path .join (data_dir , 'some_input_file.tsv' )
output_file = os .path .join (data_dir , 'some_out_file.tsv' )
def main ():
with open (input_file ) as ifo , open (output_file , mode = 'w' ) as ofo :
csv_reader = csv .reader ((x .replace ('\0' , '' ) for x in ifo ), delimiter = '\t ' , quoting = csv .QUOTE_NONE )
csv_writer = csv .writer (ofo , delimiter = '\t ' , quoting = csv .QUOTE_NONE , quotechar = '' , escapechar = '\\ ' ) # for tsv
# csv_reader = csv.reader(ifo, delimiter=',', quoting=csv.QUOTE_NONE) # for csv
# csv_writer = csv.writer(ofo, delimiter=',') # for csv
for counter , row in enumerate (csv_reader ): # extract one row
catalog_no , catalog_name = row [0 :2 ] # extract fields from a row
csv_writer .writerow ([catalog_no , catalog_name ]) # write fields to writer
if __name__ == '__main__' :
main ()
file_name = "boundary_exception.csv"
simple but use huge memory
with open (file_name ) as fo :
line_list = [line .rstrip ('\n ' ) for line in fo ]
print (line_list )