readDataFile ( attrFile )
read an annotated data file
attrFile indicates a file-like object or list of strings.
attrFile contains control lines and data lines. Control and
data lines may be freely interspersed. The data lines are of
the form: field 1 [field 2...]
The control lines are of the form:
name: value
Empty lines are ignored and lines beginning with the # character
are considered comments and ignored.
If a control line with a duplicate name is encountered, then
it is assumed that the file is basically several separate files
concatenated together (which can be convenient for defining
attributes for example). The previous data/control line are
remembered and a new set gathered from scratch.
This function returns a list of tuples, one for each "set" of
control/data lines in the file (see previous paragraph). Each
tuple consists of a dictionary of the controls lines, keyed on
name, and a list of the data line tuples (split at tabs).
Exceptions
|
|
SyntaxError( "Empty value on line %d" " of file" % lineNum )
SyntaxError, "\n".join( dataErrors )
SyntaxError( "Line %d of file is either" " not 'name: value' or is missing" " initial tab" % lineNum )
|
|