You are reading a text file that uses a different newline convention from your system; \r
where probably your system expects either \n
or \r\n
.
You can open the file using universal newline support instead with the 'rU'
mode:
data = open("banklist.csv", "rU").readlines()[1:]
The smarter way to skip that first line is to use the file as an iterator; loop over it directly. The next()
method lets you grab one line at a time, giving you a method to skip the first line:
with open("banklist.csv", "rU") as infile:
next(infile, None) # skip the first line
for line in infile:
print line
However, if this a CSV file, use the csv
module to read the data:
import csv
with open("banklist.csv", "rU") as infile:
reader = csv.reader(infile)
next(reader, None) # skip the first row
for row in reader:
print row
The CSV module handles splitting the lines into lists for you:
['First National Bank also operating as The National Bank of El Paso', 'Edinburg', 'TX', '14318', '13-Sep-13', '18-Sep-13']
["The Community's Bank", 'Bridgeport', 'CT', '57041', '13-Sep-13', '17-Sep-13']
['Sunrise Bank of Arizona', 'Phoenix', 'AZ', '34707', '23-Aug-13', '11-Sep-13']
['Community South Bank', 'Parsons', 'TN', '19849', '23-Aug-13', '5-Sep-13']
['Bank of Wausau', 'Wausau', 'WI', '35016', '9-Aug-13', '4-Sep-13']
['First Community Bank of Southwest Florida (also operating as Community Bank of Cape Coral)', 'Fort Myers', 'FL', '34943', '2-Aug-13', '26-Aug-13']
# etc.