Commits

James Taylor committed 1988f04

Fix 'first line is header' support in tabular.io

Comments (0)

Files changed (1)

lib/bx/tabular/io.py

 from itertools import *
 from UserDict import DictMixin
 
+FIRST_LINE_IS_HEADER = object()
+
 class ParseError( Exception ):
     def __init__( self, *args, **kwargs ):
         Exception.__init__( self, *args )
                 return Comment( line )
             else:
                 return self.next()
+        # Force header?
+        if self.header is FIRST_LINE_IS_HEADER and self.linenum == 1:
+            self.header = self.parse_header( line )
+            if self.return_header:
+                return self.header
+            else:
+                return self.next()
         # Is it a comment line?
         for comment_line_start in self.comment_lines_startswith:
             if line.startswith( comment_line_start ):