pyline package

Submodules

pyline.pyline module

class pyline.pyline.NullHandler(level=0)[source]

Bases: logging.Handler

emit(record)[source]
class pyline.pyline.PylineResult[source]

Bases: pyline.pyline.Result

class pyline.pyline.Result

Bases: tuple

Result(n, result)

__getnewargs__()

Return self as a plain tuple. Used by copy and pickle.

__getstate__()

Exclude the OrderedDict from pickling

__repr__()

Return a nicely formatted representation string

n

Alias for field number 0

result

Alias for field number 1

class pyline.pyline.ResultWriter(_output, *args, **kwargs)[source]

Bases: object

OUTPUT_FILETYPES = {'csv': ',', 'checkbox': True, 'json': True, 'html': True, 'tsv': '\t', 'txt': True}
filetype = None
footer(*args, **kwargs)[source]
classmethod get_writer(_output, filetype='csv', **kwargs)[source]

get writer object for _output with the specified filetype

Parameters:
  • output_filetype – txt | csv | tsv | json | html | checkbox
  • _output – output file
header(*args, **kwargs)[source]
set_output(_output)[source]
setup(*args, **kwargs)[source]
write(obj)[source]
write_numbered(obj)[source]
class pyline.pyline.ResultWriter_checkbox(_output, *args, **kwargs)[source]

Bases: pyline.pyline.ResultWriter

filetype = 'checkbox'
write(obj)[source]
class pyline.pyline.ResultWriter_csv(_output, *args, **kwargs)[source]

Bases: pyline.pyline.ResultWriter

filetype = 'csv'
header(*args, **kwargs)[source]
setup(*args, **kwargs)[source]
write(obj)[source]
write_numbered(obj)[source]
class pyline.pyline.ResultWriter_html(_output, *args, **kwargs)[source]

Bases: pyline.pyline.ResultWriter

static escape_func(s, quote=None)

Replace special characters “&”, “<” and “>” to HTML-safe sequences. If the optional flag quote is true, the quotation mark character (”) is also translated.

filetype = 'html'
footer()[source]
header(*args, **kwargs)[source]
write(obj)[source]
class pyline.pyline.ResultWriter_json(_output, *args, **kwargs)[source]

Bases: pyline.pyline.ResultWriter

filetype = 'json'
write(obj)[source]
write_numbered(obj)
class pyline.pyline.ResultWriter_txt(_output, *args, **kwargs)[source]

Bases: pyline.pyline.ResultWriter

filetype = 'txt'
write_numbered(obj)[source]
pyline.pyline.build_column_map(col_map)[source]
Parameters:col_map (str or dict) – col_mapstr or a dict
Returns:or OrderedDict of (col, type_func) mappings
Return type:dict
pyline.pyline.get_list_from_str(str_, idelim=', ', type_func=<type 'int'>)[source]

Split a string of integers separated by commas

pyline.pyline.get_option_parser()[source]
pyline.pyline.get_sort_function(opts, col_map=None)[source]
pyline.pyline.main(*args)[source]
pyline.pyline.parse_column_map(col_mapstr, default=<type 'unicode'>)[source]
Parameters:col_mapstr (str) – e.g. “0,1,2,3” or “0,1,4:int”
Keyword Arguments:
 default (callable) – type casting callable
Yields:tuple – (col, type casting function)
pyline.pyline.pyline(iterable, cmd=None, col_map=None, modules=, []regex=None, regex_options=None, path_tools_pathpy=False, path_tools_pathlib=False, shlex=None, idelim=None, idelim_split_max=-1, odelim='\t', **kwargs)[source]

Process an iterable of lines

Parameters:
  • iterable (iterable) – iterable of strings (e.g. sys.stdin or a file)
  • cmd (str) – python command string
  • modules ([str]) – list of modules to import
  • regex (str) – regex pattern to match (with groups)
  • regex_options (TODO) – Regex options: I L M S X U (see pydoc re)
  • path_tools (bool) – try to cast each line to a file
  • idelim (str) – input delimiter
  • idelim_split_max (int) – str.split(idelim, idelim_split_max)
  • odelim (str) – output delimiter
Returns:

iterable of PylineResult namedtuples

pyline.pyline.sort_by(sortstr, iterable, reverse=False, col_map=None, default_type=None, default_value=None)[source]
Parameters:
  • sortstr (str) – sort string (comma separated list of column numbers)
  • iterable (iterable) – iterable of lines/rows
Keyword Arguments:
 

reverse (bool) – True to sort in reverse

Returns:

sorted list of lines/rows

Return type:

list

Module contents