Python CSV阅读器不会读取行

时间:2017-02-27 03:43:54

标签: python csv

出于某种原因,我无法让csv阅读器读取任何行。我使用IDLE编辑文本并运行Python 3.4。文件正在打开,我可以从文件中获取纯文本。我试图使用阅读器循环访问csv,以便我可以编辑某些列的某些项目。该程序正在将文件中的人员组织成两个单独的文件。这是我的代码:

# Desc: File used to split single data file into two separate files, based
#       on whether the person has been terminated from the program or not.
#
# Written in Python 3.4
# Last updated: 2/26/2017

import csv

datafile = "mow-data.csv" # the raw data
fileCurrent = "mow-data-current.csv" # data of people still in the program
fileTerminated = "mow-data-terminated.csv" # data of people no longer in the program

# Open read and write files and create csv reader and writer
readFile = open(datafile, 'r')
readFileText = readFile.read()
reader = csv.reader(readFile, delimiter=',')

writeFileCurrent = open(fileCurrent, 'w')
writeFileTerminated = open(fileTerminated, 'w')
writerCurr = csv.writer(writeFileCurrent, delimiter=',')
writerTerm = csv.writer(writeFileTerminated, delimiter=',')

# Loop through every row in csv
for row in reader:
    writerCurr.writerow(row) ### testing
    print("test") ### testing


# Closing the files
readFile.close()
writeFileCurrent.close()
writeFileTerminated.close()

### END OF FILE

出于某种原因,for循环似乎没有做任何事情。有帮助吗?此外,这里有一些csv文件,我使用了很多个人信息更改:

address1,address2,city,state,zipcode,date1,column7,date2,level,date3,date4,reason,date5,data2
1234 FAKE ST.,,NOWHERE,KY,48880,18-Feb-12,CLIENT,1-Sep-53,,1-Oct-93,6-Jul-04,DE,2-Dec-98,Y
4908 NOTREAL AVE,,SOMEWHERE,MO,46212,21-Jun-21,CLIENT,10-Nov-97,,1-May-92,3-Jan-07,DE,1-Dec-78,Y

0 个答案:

没有答案