Reading and writing data tables with types and uncertainties (pwkit.tabfile
)¶
pwkit.tabfile - I/O with typed tables of uncertain measurements.
Functions:
read - Read a typed table file. vizread - Read a headerless table file, with columns specified separately write - Write a typed table file.
The table format is line-oriented text. Hashes denote comments. Initial lines of the form “colname = value” set a column name that gets the same value for every item in the table. The header line is prefixed with an @ sign. Subsequent lines are data rows.
- pwkit.tabfile.read(path, tabwidth=8, **kwargs)[source]¶
Read a typed tabular text file into a stream of Holders.
Arguments:
- path
The path of the file to read.
- tabwidth=8
The tab width to assume. Please don’t monkey with it.
- mode=’rt’
The file open mode (passed to io.open()).
- noexistok=False
If True and the file is missing, treat it as empty.
**kwargs
Passed to io.open ().
Returns a generator for a stream of pwkit.Holder`s, each of which will contain ints, strings, or some kind of measurement (cf `pwkit.msmt).
- pwkit.tabfile.vizread(descpath, descsection, tabpath, tabwidth=8, **kwargs)[source]¶
Read a headerless tabular text file into a stream of Holders.
Arguments:
- descpath
The path of the table description ini file.
- descsection
The section in the description file to use.
- tabpath
The path to the actual table data.
- tabwidth=8
The tab width to assume. Please don’t monkey with it.
- mode=’rt’
The table file open mode (passed to io.open()).
- noexistok=False
If True and the file is missing, treat it as empty.
**kwargs
Passed to io.open ().
Returns a generator of a stream of pwkit.Holder`s, each of which will contain ints, strings, or some kind of measurement (cf `pwkit.msmt). In this version, the table file does not contain a header, as seen in Vizier data files. The corresponding section in the description ini file has keys of the form “colname = <start> <end> [type]”, where <start> and <end> are the 1-based character numbers defining the column, and [type] is an optional specified of the measurement type of the column (one of the usual b, i, f, u, Lu, Pu).
- pwkit.tabfile.write(stream, items, fieldnames, tabwidth=8)[source]¶
Write a typed tabular text file to the specified stream.
Arguments:
- stream
The destination stream.
- items
An iterable of items to write. Two passes have to be made over the items (to discover the needed column widths), so this will be saved into a list.
- fieldnames
Either a list of field name strings, or a single string. If the latter, it will be split into a list with .split().
- tabwidth=8
The tab width to use. Please don’t monkey with it.
Returns nothing.