pyline package¶
Submodules¶
pyline.pyline module¶
-
class
pyline.pyline.
PylineResult
[source]¶ Bases:
pyline.pyline.Result
-
class
pyline.pyline.
Result
(n, result)¶ Bases:
tuple
-
__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¶
-
-
class
pyline.pyline.
ResultWriter_checkbox
(_output, *args, **kwargs)[source]¶ Bases:
pyline.pyline.ResultWriter
-
filetype
= 'checkbox'¶
-
-
class
pyline.pyline.
ResultWriter_csv
(_output, *args, **kwargs)[source]¶ Bases:
pyline.pyline.ResultWriter
-
filetype
= 'csv'¶
-
-
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'¶
-
static
-
class
pyline.pyline.
ResultWriter_json
(_output, *args, **kwargs)[source]¶ Bases:
pyline.pyline.ResultWriter
-
filetype
= 'json'¶
-
write_numbered
(obj)¶
-
-
class
pyline.pyline.
ResultWriter_txt
(_output, *args, **kwargs)[source]¶ Bases:
pyline.pyline.ResultWriter
-
filetype
= 'txt'¶
-
-
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.
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, codefunc=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
- codefunc (callable) – alternative to cmd
codefunc(locals())
- 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