pwtools.sql.sql_column

pwtools.sql.sql_column(key, lst, sqltype=None, sqlval_func=<function <lambda>>, fileval_func=<function <lambda>>)[source]

Convert a list lst of values of the same type (i.e. all floats) to a list of SQLEntry instances of the same column name key and sqltype (e.g. ‘float’).

See ParameterStudy for applications.

Parameters:
  • key (str) – sql column name

  • lst (sequence of arbitrary values, these will be SQLEntry.sqlval) –

  • sqltype (str, optional) – sqlite type, if None then it is determined from the first entry in lst (possibly modified by sqlval_func)

  • sqlval_func (callable, optional) – Function to transform each entry lst[i] to SQLEntry.sqlval Default is sqlval = lst[i].

  • fileval_func (callable, optional) –

    Function to transform each entry lst[i] to SQLEntry.fileval Default is fileval = lst[i].

    example:

    >>> lst[i] = '23'
    >>> fileval = 'value = 23'
    >>> fileval_func = lambda x: "value = %s" %str(x)
    

Examples

>>> vals = sql_column('ecutfwc', [25.0, 50.0, 75.0],
...                   fileval_func=lambda x: 'ecutfwc=%s'%x)
>>> for v in vals:
...     print(v.key, v.sqltype, v.sqlval, v.fileval)
ecutfwc REAL 25.0 ecutfwc=25.0
ecutfwc REAL 50.0 ecutfwc=50.0
ecutfwc REAL 75.0 ecutfwc=75.0