I’m trying to simply open a csv file, and print out the rows in that file. When I pass the file as a string to this function, the output is the content of the string, not the rows of the file.
def _print_rows(filename):
with open(filename, 'rt') as opened_file:
read_file = csv.reader(opened_file):
for row in read_file:
print row
raw_input()
opened_file.close()
>>> module_name._print_rows('first_class_profile.csv')
['f']
['i']
['r']
['s']
['t']
['_']
Considering that the code you posted has errors I think you did not post your actual code.
Your
_print_rowsfunction is actually printing the characters in the filename, rather than the contents of the file. This would occur if you passed the filename of your csv file to thecsv.readerrather than the opened file: