From 81e2ada60c4ac7a130c64c030b522390e07c2fd9 Mon Sep 17 00:00:00 2001 From: wirawan Date: Fri, 16 Sep 2011 21:21:23 +0000 Subject: [PATCH] * Allow comment character to be changed from "#" using the instance.comment_char attribute. --- iofmt/text_input.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/iofmt/text_input.py b/iofmt/text_input.py index 05929ed..5f3efd4 100644 --- a/iofmt/text_input.py +++ b/iofmt/text_input.py @@ -1,5 +1,5 @@ #!/usr/bin/python -# $Id: text_input.py,v 1.5 2011-09-05 19:09:21 wirawan Exp $ +# $Id: text_input.py,v 1.6 2011-09-16 21:21:23 wirawan Exp $ # # wpylib.iofmt.text_input module # Quick-n-dirty text input utilities @@ -82,19 +82,21 @@ class text_input(object): def next_rec(self): '''Yields the next record, which is already separated into fields.''' + comment_char = getattr(self, "comment_char", "#") while True: self.lineno += 1 L = self.file.next() - F = self.field_filtering_proc(L.split("#")[0].split()) + F = self.field_filtering_proc(L.split(comment_char)[0].split()) if len(F) > 0 or not self.skip_blank_lines: return F def next_line(self): '''Yields the next line, which is already separated into fields.''' + comment_char = getattr(self, "comment_char", "#") while True: self.lineno += 1 L = self.file.next() - F = self.field_filtering_proc(L.split("#")[0].rstrip()) + F = self.field_filtering_proc(L.split(comment_char)[0].rstrip()) if len(F) > 0 or not self.skip_blank_lines: return F