def get_vocabulary(current_pos=1):
"""
get_vocabulary returns a single record of the current_pos line position
current_pos: up to number of records
"""
vocabulary = {}
with open(VOCABULARY_FILENAME, 'rb') as fobj:
reader = csv.reader(fobj, delimiter=',', encoding='utf-8')
num_of_lines = 0
for line in reader:
num_of_lines += 1
if num_of_lines == current_pos:
vocabulary = dict(zip(VOCABULARY_FIELDS, line))
break
# Convert to UTF-8
for key, value in vocabulary.iteritems():
vocabulary[key] = value.encode("utf-8")
return vocabulary
评论列表
文章目录