71.8k views
3 votes
For the deliverables, you will need a delimited text file.  You can find many of them on the web, or you can make one yourself.  The minimum is 100 rows, two columns of date.  Please write a program that reads the file and displays it, then writes the file to another text file

User Elgoog
by
7.9k points

1 Answer

2 votes

Below is a Python script that reads a CSV file, displays its content, and writes it to another text file.

import csv

def read_and_display(input_file):

with open(input_file, 'r') as file:

reader = csv.reader(file)

for row in reader:

print(row)

def write_to_file(input_file, output_file):

with open(input_file, 'r') as infile, open(output_file, 'w', newline='') as outfile:

reader = csv.reader(infile)

writer = csv.writer(outfile)

for row in reader:

writer.writerow(row)

if __name__ == "__main__":

# Replace 'input.csv' with the path to your input file

input_file_path = 'input.csv'

# Replace 'output.csv' with the path to your output file

output_file_path = 'output.csv'

User Vivek S
by
7.9k points