Where did csv.parser() go?

jason at apkudo.com jason at apkudo.com
Tue Jan 2 11:59:13 EST 2018


I need record the starting offsets of csv rows in a database for fast seeking later. 
Unfortunately, using any csv.reader() (or DictReader) tries to cache, which means:
example_Data = "'data
0123456789ABCDE
1123456789ABCDE
2123456789ABCDE
3123456789ABCDE
...
'''

for line in reader:
    offsets[row] = f.tell() 

is not possible. With my example data , offsets are reported as [0, 260, 260, 260...] they should be [0x00, 0x00,0x15, 0x25, ...] (sample data is 16 byte rows after a 5 byte header (just for now)) 

I saw in one of PEP-305's references a mention of csv.parser() which won't return a row until parsing is complete. This is ideal since some lines will have quoted text containing commas and new lines.  I don't want to re-write the parser, since later usage will use csvDictReader, so we need to identically parse rows. How can I do that with the Python 2.7 csv module?

Or how can I accomplish this task through other means?



More information about the Python-list mailing list