-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport_csv.py
More file actions
35 lines (29 loc) · 1000 Bytes
/
import_csv.py
File metadata and controls
35 lines (29 loc) · 1000 Bytes
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
import csv
# csvfile = 'dpx_offsets.csv'
# start_byte = reader
def get_offsets(csvfile, field):
start_byte = None
end_byte = None
with open(csvfile, encoding="UTF-8") as datafile:
# assert os.path.exists(csvfile)
reader = csv.DictReader(datafile)
foo = []
try:
for entry in reader:
foo.append(entry)
except:
pass
# print(entry)
# print(csvfile)
for entry in foo:
if entry['title'] == field:
start_byte = int(entry['startByte'])
end_byte = int(entry['endByte'])
# print("Found {}".format(field))
break
if start_byte is not None and end_byte is not None:
# print(start_byte, end_byte)
return int(start_byte), int(end_byte)
else:
raise Exception("Missing field \"{}\"".format(field))
# get_offsets("D:/sandbox/projects/python/dpx/DPXdpxDPX/dpx_offsets.csv", "Creator")