BaseReader¶
-
class
astropy.io.ascii.
BaseReader
[source] [edit on github]¶ Bases:
object
Class providing methods to read and write an ASCII table using the specified header, data, inputter, and outputter instances.
Typical usage is to instantiate a Reader() object and customize the
header
,data
,inputter
, andoutputter
attributes. Each of these is an object of the corresponding class.There is one method
inconsistent_handler
that can be used to customize the behavior ofread()
in the event that a data row doesn’t match the header. The default behavior is to raise an InconsistentTableError.Attributes Summary
comment_lines
Return lines in the table that match header.comment regexp encoding
exclude_names
guessing
include_names
names
strict_names
Methods Summary
inconsistent_handler
(str_vals, ncols)Adjust or skip data entries if a row is inconsistent with the header. read
(table)Read the table
and return the results in a format determined by theoutputter
attribute.update_table_data
(table)Update table columns in place if needed. write
(table)Write table
as list of strings.write_header
(lines, meta)Attributes Documentation
-
comment_lines
¶ Return lines in the table that match header.comment regexp
-
encoding
= None¶
-
exclude_names
= None¶
-
guessing
= False¶
-
include_names
= None¶
-
names
= None¶
-
strict_names
= False¶
Methods Documentation
-
inconsistent_handler
(str_vals, ncols)[source] [edit on github]¶ Adjust or skip data entries if a row is inconsistent with the header.
The default implementation does no adjustment, and hence will always trigger an exception in read() any time the number of data entries does not match the header.
Note that this will not be called if the row already matches the header.
Parameters: - str_vals : list
A list of value strings from the current row of the table.
- ncols : int
The expected number of entries from the table header.
Returns: - str_vals : list
List of strings to be parsed into data entries in the output table. If the length of this list does not match
ncols
, an exception will be raised in read(). Can also be None, in which case the row will be skipped.
-
read
(table)[source] [edit on github]¶ Read the
table
and return the results in a format determined by theoutputter
attribute.The
table
parameter is any string or object that can be processed by the instanceinputter
. For the base Inputter classtable
can be one of:- File name
- File-like object
- String (newline separated) with all header and data lines (must have at least 2 lines)
- List of strings
Parameters: - table : str, file_like, list
Input table.
Returns: - table :
Table
Output table
-
update_table_data
(table)[source] [edit on github]¶ Update table columns in place if needed.
This is a hook to allow updating the table columns after name filtering but before setting up to write the data. This is currently only used by ECSV and is otherwise just a pass-through.
Parameters: - table :
astropy.table.Table
Input table for writing
Returns: - table :
astropy.table.Table
Output table for writing
- table :
-
write
(table)[source] [edit on github]¶ Write
table
as list of strings.Parameters: - table :
Table
Input table data.
Returns: - lines : list
List of strings corresponding to ASCII table
- table :
-
write_header
(lines, meta)[source] [edit on github]¶
-