I'm trying to read a csv file but for some reason when I ask it to print, it prints the memory address instead of the table.
Below is my result :
>>> read_table('books.csv')
['books.csv', 'boxoffice.csv', 'imdb.csv', 'olympics-locations.csv', 'olympics-results.csv', 'oscar-actor.csv', 'oscar-film.csv', 'seinfeld-episodes.csv', 'seinfeld-foods.csv']
<_csv.reader object at 0x03977C30>
This is my code :
import csv
import glob
from database import *
def read_table(name):
'''
(str) -> Table
Given a file name as a string, the function will return the file as a Table
object.
'''
# create a list that stores all comma-separate files(*.csv)
files_list = glob.glob('*.csv')
print(files_list)
# check if the desired file is in the list
if(name in files_list):
# if found, open the file for reading
with open(name) as csvfile:
readCSV = csv.reader(csvfile, delimiter = ',')
print(readCSV)
Something is false in my script ?
csv.readerreturns a reader object which will iterate over lines in the given csvfile. So in order to print the file, you should iterate over the object, for each iteration the object will return a new line of data. This line can then be printed if that is desired.