-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSV Reader.py
More file actions
40 lines (32 loc) · 1.07 KB
/
CSV Reader.py
File metadata and controls
40 lines (32 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
__author__ = 'Charlie'
# The Goal of this script is to read from a CSV file and
# produce a double nested list
import csv # don't forget your import statement
def readCSV(filelocation):
'''filelocation should be the directory of a file that
you want to read inputted as a string. If the file
is in the same direcotry then you can just input
the filename.
'''
#try to convert the filename to a string, in case it wasn't already
try:
filelocation = str(filelocation)
except:
return print('please pass in a valid file location string')
#The following is a slightly modifyied version of the code in HW4 skeleton
f = open(filelocation)
reader = csv.reader(f)
#read in data, convert to ints where possible, leave as strings otherwise
data = []
for i in reader:
temp = []
for j in i:
try:
j = int(j)
temp.append(j)
except:
temp.append(j)
data.append(temp)
return data
def SomeNewFunction(item):
print(item)