Package recsql :: Module rest_table :: Class Table2array
[hide private]
[frames] | no frames]

Class Table2array

source code

object --+
         |
        Table2array

Primitive parser that converts a simple reST table into ``numpy.recarray``.

The table must be the only table in the text. It must look similar to the
example below (variable parts in angle brackets, optional in double
brackets, everything else must be there, matching is case sensitive, '....'
signifies repetition in kind)::

  Table[<NAME>]: <<CAPTION>>
  ============  ===========  ======================  ....
  <COLNAME 1>   <COLNAME 2>  ....                    ....
  ============  ===========  ======================  ....
  <VALUE>       <VALUE>      <VALUE> <VALUE> ....
  ....
  ....
  ============  ===========  ======================  ....

Rows may *not* span multiple lines. The column names must be single words
and legal python names (no spaces, no dots, not starting with a number).

Field values are converted to one of the following python types: *int*,
*float*, or *str*.

If a value is quote with single or double quotation marks then the
outermost quotation marks are stripped and the enclosed value treated as a string.

.. Note:: Values such as 001 must be quoted as '001' or they will be
          interpreted as integers (1 in this case).

Instance Methods [hide private]
 
__init__(self, string=None, **kwargs)
Table2array(string) --> parser
source code
 
parse(self)
Parse the table data string into records.
source code
 
recarray(self)
Return a recarray from the (parsed) string.
source code
 
parse_fields(self)
Determine the start and end columns and names of the fields.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Instance Variables [hide private]
  tablename
<NAME> of the table
  caption
<CAPTION> of the table.
  records
parsed table as records (populate with :meth:`Table2array.parse`)
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, string=None, **kwargs)
(Constructor)

source code 
Table2array(string) --> parser

:Arguments:
   *string*
      string to be parsed
   *filename*
      read from *filename* instead of string
   *autoconvert*
      EXPERIMENTAL. ``True``: replace certain values
      with special python values (see :class:`convert.Autoconverter`) and possibly 
      split values into lists (see *sep*).
      ``False``: leave everything as it is (numbers as numbers and strings 
      as strings).
   *mode*
      mode of the :class:`~convert.Autoconverter`
   *sep*
      If set and *autoconvert* = ``True`` then split field values on the
      separator (using :func:`split`) before possible autoconversion.
      (NOT WORKING PROPERLY YET)

Overrides: object.__init__