comma.classes package¶
Submodules¶
comma.classes.file module¶
-
class
comma.classes.file.
CommaFile
(header=None, primary_key=None, params=None)¶ Bases:
object
Store the metadata associated with a CSV/DSV file. This includes the header (a list of column names) if it exists; the primary_key (that is, whether one of the columns should function as an index for rows); and the internal parameters, such as dialect and encoding, that are detetcted when the table data was loaded.
-
property
header
¶ The header of the associated CommaFile, if such a header has been defined and None otherwise. The header is a list of strings, which are the names of the column of the dataset table. When specified, it is possible to access the columns of the associated CommaTable by their name, both to get a column-slice of the dataset, or the access that field in a row.
-
property
primary_key
¶ This property can be set when the header property has also been defined. It should be either None (if unset) or the name of a column of header. The associated CommaTable will then allow for the access of records indexed by the column of that same name.
-
property
comma.classes.row module¶
-
class
comma.classes.row.
CommaRow
(initlist=None, parent=None, slice_list=None, original=None, *args, **kwargs)¶ Bases:
collections.UserList
,list
,collections.UserDict
Contains a single row of a CSV file; the row contains only data stored in the row, and a pointer to a parent file structure (which stores all the extraneous information, such as dialect and header).
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
property
header
¶
-
items
() → a set-like object providing a view on D’s items¶
-
keys
() → a set-like object providing a view on D’s keys¶
-
values
() → an object providing a view on D’s values¶
-
comma.classes.slices module¶
-
class
comma.classes.slices.
CommaFieldSlice
(initlist=None, parent=None, field_name=None, *args, **kwargs)¶ Bases:
list
,collections.UserList
Contains a column of a CSV file.
comma.classes.table module¶
-
class
comma.classes.table.
CommaTable
(initlist=None, parent=None, *args, **kwargs)¶ Bases:
collections.UserList
,list
,collections.UserDict
,comma.abstract.CloneableCollection
Contains a table from a CSV file. This is a subclass of collections.UserList, and it can be manipulated in many regards like a list, including in modifications.
Let table be an instance of this class. You can access the items by index:
` table[0] # => ["row1col1", "row1col2", "row1col3"] ``
would be the first row.If the CommaTable has a header, it can be accessed at table.header, and should be a list of strings. When it is set it allow for a column-wise access: ``` table.header = [“column1”, “column2”, “column3”] table[“column1”] # => [“row1col1”, “row2col1”, “row3col1”, “row4col3”] table[0] = {
“column1”: “row1col1”, “column2”: “row1col2”, “column3”: “row1col3”, “column4”: “row1col4”,
As shown with table[0], individual rows can also be accessed as dictionaries, as another consequence of having the header specified. (Note: That the row indexing is still available, since the dictionary keys are strings.)
The rows can be modified in place.
-
dump
(filename=None, fp=None)¶ Outputs a serialization of this CommaTable object to a string, either as a return value, or written to a local file path filename, or a stream fp.
- Parameters
filename (Optional[str]) –
fp (Optional[IO]) –
- Return type
str
-
property
has_header
¶ Checks whether the CommaTable has a header as provided in the data source, or as later provided by the user.
-
property
header
¶ Property providing a header with column names for the columns of the data stored by this CommaTable object. The header may come either from the parent CommaFile object (and is sourced from the original data source), or can be user-provided, for instance by setting this property.
-
property
primary_key
¶ Property controlling whether the CommaTable is indexed by one of its columns. This allows for using a column, for instance username or userid or email, as a primary key for the rows of the CommaTable.
-
to_html
()¶ Returns an HTML string representation of the table data.
-
Module contents¶
-
class
comma.classes.
CommaFieldSlice
(initlist=None, parent=None, field_name=None, *args, **kwargs)¶ Bases:
list
,collections.UserList
Contains a column of a CSV file.
-
class
comma.classes.
CommaFile
(header=None, primary_key=None, params=None)¶ Bases:
object
Store the metadata associated with a CSV/DSV file. This includes the header (a list of column names) if it exists; the primary_key (that is, whether one of the columns should function as an index for rows); and the internal parameters, such as dialect and encoding, that are detetcted when the table data was loaded.
-
property
header
¶ The header of the associated CommaFile, if such a header has been defined and None otherwise. The header is a list of strings, which are the names of the column of the dataset table. When specified, it is possible to access the columns of the associated CommaTable by their name, both to get a column-slice of the dataset, or the access that field in a row.
-
property
primary_key
¶ This property can be set when the header property has also been defined. It should be either None (if unset) or the name of a column of header. The associated CommaTable will then allow for the access of records indexed by the column of that same name.
-
property
-
class
comma.classes.
CommaRow
(initlist=None, parent=None, slice_list=None, original=None, *args, **kwargs)¶ Bases:
collections.UserList
,list
,collections.UserDict
Contains a single row of a CSV file; the row contains only data stored in the row, and a pointer to a parent file structure (which stores all the extraneous information, such as dialect and header).
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
property
header
¶
-
items
() → a set-like object providing a view on D’s items¶
-
keys
() → a set-like object providing a view on D’s keys¶
-
values
() → an object providing a view on D’s values¶
-
-
class
comma.classes.
CommaTable
(initlist=None, parent=None, *args, **kwargs)¶ Bases:
collections.UserList
,list
,collections.UserDict
,comma.abstract.CloneableCollection
Contains a table from a CSV file. This is a subclass of collections.UserList, and it can be manipulated in many regards like a list, including in modifications.
Let table be an instance of this class. You can access the items by index:
` table[0] # => ["row1col1", "row1col2", "row1col3"] ``
would be the first row.If the CommaTable has a header, it can be accessed at table.header, and should be a list of strings. When it is set it allow for a column-wise access: ``` table.header = [“column1”, “column2”, “column3”] table[“column1”] # => [“row1col1”, “row2col1”, “row3col1”, “row4col3”] table[0] = {
“column1”: “row1col1”, “column2”: “row1col2”, “column3”: “row1col3”, “column4”: “row1col4”,
As shown with table[0], individual rows can also be accessed as dictionaries, as another consequence of having the header specified. (Note: That the row indexing is still available, since the dictionary keys are strings.)
The rows can be modified in place.
-
dump
(filename=None, fp=None)¶ Outputs a serialization of this CommaTable object to a string, either as a return value, or written to a local file path filename, or a stream fp.
- Parameters
filename (Optional[str]) –
fp (Optional[IO]) –
- Return type
str
-
property
has_header
¶ Checks whether the CommaTable has a header as provided in the data source, or as later provided by the user.
-
property
header
¶ Property providing a header with column names for the columns of the data stored by this CommaTable object. The header may come either from the parent CommaFile object (and is sourced from the original data source), or can be user-provided, for instance by setting this property.
-
property
primary_key
¶ Property controlling whether the CommaTable is indexed by one of its columns. This allows for using a column, for instance username or userid or email, as a primary key for the rows of the CommaTable.
-
to_html
()¶ Returns an HTML string representation of the table data.
-