Wednesday, June 26, 2013

Another Iteration...

Some time you have to throw a small script together to fix an issue. When you deal with third party data that's manually generated sometimes you have to take what they give you.

I had to determine the start the field positions in a fixed record length text file by the position of the double quotes in the file. After some research I conclude to use a regular expression with an iterator.


import re

text = 'Some Long" Record with " lots of '
pattern = re.compile('"')
print [m.start() for m in pattern.finditer(text)]

No comments:

Post a Comment