Package gmisclib :: Module fiatio :: Class writer
[frames] | no frames]

Class writer

source code


Write a file in FIAT format. This class represents an open file, and you call member functions to write data into the file. This automatically generates much of the header information.

Column names are set from the keys passed in the datum() method. Each unique key generates a column, and the values are printed in the data section of the FIAT file. The TTYPE header lines will also be automatically generated.

Instance Methods
 
comment(self, comment)
Add a comment to the data file.
source code
 
header(self, k, v)
Add a single key=value line to the header of the data file.
source code
 
__init__(self, fd, sep='\t', blank='%na')
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
add_cols(self, colnames) source code
 
datum(self, data_item)
Write a line into a fiat file.
source code
 
datavec(self, vector, numeric=False)
This assumes that you've already called add_cols() to set the column names.
source code
 
append(self, d) (Inherited from gmisclib.gpk_writer.writer) source code
 
close(self) (Inherited from gmisclib.gpk_writer.writer) source code
 
comments(self, comments)
Add comments to the data file. (Inherited from gmisclib.gpk_writer.writer)
source code
 
data(self, dataset)
Write a series of lines to the output file. (Inherited from gmisclib.gpk_writer.writer)
source code
 
extend(self, d) (Inherited from gmisclib.gpk_writer.writer) source code
 
flush(self) (Inherited from gmisclib.gpk_writer.writer) source code
 
headers(self, h) (Inherited from gmisclib.gpk_writer.writer) source code

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

Properties

Inherited from object: __class__

Method Details

comment(self, comment)

source code 

Add a comment to the data file.

Parameters:
  • comment (str) - the comment
Overrides: gpk_writer.writer.comment

header(self, k, v)

source code 

Add a single key=value line to the header of the data file.

Parameters:
  • k (str) - key
  • v (str) - value
Overrides: gpk_writer.writer.header

__init__(self, fd, sep='\t', blank='%na')
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Parameters:
  • fd (file) - where to write the data
  • sep (str) - what separates columns?
  • blank (str) - what marks a spot where there isn't data?
Overrides: object.__init__

datum(self, data_item)

source code 

Write a line into a fiat file. They column names will be set from the keys.

Parameters:
  • data_item (dict(str: anything)) - a dictionary of key=value pairs.
Overrides: gpk_writer.writer.datum

datavec(self, vector, numeric=False)

source code 

This assumes that you've already called add_cols() to set the column names. It is an error to have a vector whose length doesn't match the number of column names.