speriment.utils
index
/Users/presley/Speriment/speriment/utils.py

 
Modules
       
csv
itertools

 
Classes
       
IDGenerator

 
class IDGenerator
    Creates an object to generate unique IDs for experimental components. You
should create exactly one per experiment so that all IDs in that experiment
will be distinct.
 
Usage:
with make_experiment(IDGenerator()):
    <experiment code>
 
  Methods defined here:
__init__(self, seed=-1)
seed: optional, an integer to start making IDs at.

 
Functions
       
get_dicts(csvfile, sep=',')
csvfile: string, a filename of a csv file. The file should have a header
row with column names.
 
sep: string, the delimiter used to separate values in the csv file. Defaults
to comma.
 
Returns: lists (one for each row in the file) of dictionaries mapping
strings (column names) to strings (cell values).
get_rows(csvfile, sep=',')
csvfile: string, a filename of a csv file.
 
sep: string, the delimiter used to separate values in the csv file. Defaults
to comma.
 
Returns: lists (one for each row in the file) of lists (one for each cell in
the row) of strings.
group_by_col(rows, column)
rows: [[string]] (output of get_rows) or [{string: string}] (output of
get_dicts).
 
column: integer if [[string]], string if [{string: string}].
 
Returns: {column: rows}, a dictionary whose keys are the unique values in
the column provided, where each column value maps to a list of all rows with
that value.
make_experiment(id_generator)
id_generator: IDGenerator, an object that will make unique IDs for
everything in an Experiment.
 
side effect: puts id_generator in scope for the duration of the with block.
Options, Pages, and Blocks will automatically use it to create unique IDs.
 
Usage:
with make_experiment(IDGenerator()):
    <experiment code>
 
<any code here will not use that IDGenerator anymore>

 
Data
        __all__ = ['get_rows', 'get_dicts', 'group_by_col', 'IDGenerator', 'make_experiment']