CSV reader ignore brackets
Cameron Simpson
cs at cskk.id.au
Tue Sep 24 21:09:28 EDT 2019
On 24Sep2019 19:02, Skip Montanaro <skip.montanaro at gmail.com> wrote:
>How about just replacing *\(([^)]*)\)* with *"\1"* in a wrapper class's
>line reading method?
Will that work if the OP's (TEST1,TEST2) term itself contains quotes?
Not that his example data did, but example data are usually incomplete
:-)
Also, that would match FOO(TEST1,TEST2)BAH as well (making
FOO"(TEST1,TEST2)"BAH. Which might be wanted, or be not wanted or be
bad data (including but not restricted to csv module unparsable data).
I was deliberately being very conservative and kind of treating brackets
like quotes (needest at start and end) but not trying to hit things in
one go. Better to match exactly the special case you expect and then
scour of mismatches than to incorrectly match and have that mistake
buried in the data.
>(I think I have the re syntax approximately right.)
>The csv reader will "just work". Again, nesting parens not allowed.
Otherwise, a neat idea.
<snark>Besides, the point isn't the shortest code but to illustrate the
idea of handling special syntax.</snark>
Cheers,
Cameron Simpson <cs at cskk.id.au>
More information about the Python-list
mailing list