#first import the csv module
import csv
#open the text file in read mode
text_file = open("randomaddresses.txt","r")
for line in text_file:
line.rstrip("\n")
#open a csv file in write mode
csv_file = open("randomaddresses.csv", "w")
reader = csv.reader(text_file, delimiter= ",")
writer = csv.writer(csv_file)
writer.writerow(["Address","City","State","Zip Code"])
for row in reader:
writer.writerow(row)
#close the two files
text_file.close()
csv_file.close()
I'm trying to get my code to show output in the csv file but when I open it up all I get is my first row but none of the addresses show up.
the data in the text file is this:
371 Arch Street
Cranford, NJ 07016
679 Race Street
Lockport, NY 14094
579 7th Avenue
Santa Clara, CA 95050
12 West Street
Orange Park, FL 32065
906 2nd Street West
Great Falls, MT 59404
851 Locust Lane
Lombard, IL 60148
837 Fawn Court
Centereach, NY 11720
343 Jefferson Court
Norwalk, CT 06851
34 3rd Street North
Athens, GA 30605
143 10th Street
North Wales, PA 19454
I would like to get each one in a cell in excel under the Address,City,State,and Zip heading.