Skip to content

Commit 6cfa463

Browse files
committed
added public property for csv headers
1 parent 91d267e commit 6cfa463

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

randomAccessReader/__init__.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,15 @@ def __init__(self, filepath, has_header=True, endline_character='\n', values_del
8282
self._quotechar = quotechar
8383
self.has_header = has_header
8484
if has_header:
85-
reader = RandomAccessReader(filepath, endline_character)
86-
self._headers = self._get_line_values(reader.get_lines(0)[0])
85+
dialect = self.MyDialect(self._endline, self._quotechar, self._delimiter)
86+
b = StringIO.StringIO(self.get_lines(0)[0])
87+
r = csv.reader(b, dialect)
88+
values = tuple(r.next())
89+
self._headers = values
90+
91+
@property
92+
def headers(self):
93+
return self._headers
8794

8895
def set_headers(self, header_list):
8996
if not hasattr(header_list, '__iter__'):
@@ -113,7 +120,7 @@ def get_line_dicts(self, line_number, amount=1):
113120
"""
114121
if not self._headers:
115122
raise ValueError("Headers must be set before requesting a line dictionary")
116-
if self._has_header:
123+
if self.has_header:
117124
line_number += 1
118125
lines = []
119126
text_lines = self.get_lines(line_number, amount)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# Versions should comply with PEP440. For a discussion on single-sourcing
1616
# the version across setup.py and the project code, see
1717
# https://packaging.python.org/en/latest/single_source_version.html
18-
version='0.2.2',
18+
version='0.2.5',
1919

2020
description='A python random access file reader',
2121
long_description=long_description,

0 commit comments

Comments
 (0)