pylib.data module

Read and write data to or from file and manipulate data structures.

Date

2019-10-11

fold_list(lst, n)[source]

Convert one-dimensional kx1 array (list) to two-dimensional mxn array. m = k / n

Parameters
  • lst (list) – list to convert

  • n (int) – length of the second dimenson

Returns

two-dimensional array (list of lists)

Return type

list

get_id(ids, uide)[source]

Get full id from unique id ending.

Parameters
  • ids (list) – ids

  • uide (str) – unique id ending

Returns

full id

Return type

str or int

issequence(obj)[source]

True for tuple, list, str False for int, dict, set

Example

>>> issequence(())
True
>>> issequence((3, ))
True
>>> issequence([])
True
>>> issequence([1])
True
>>> issequence([1, 2])
True
>>> issequence('')
True
>>> issequence((3))
False
>>> issequence({})
False
>>> issequence(set())
False
load(file_name, default=None, verbose=False)[source]

Load stored program objects from binary file.

Parameters
  • file_name (str) – file to load

  • default (object) – return object if data loading fails

  • verbose (bool) – verbose information (default = False)

Returns

loaded data

Return type

object

read(file_name, x_column, y_column, default=None, verbose=False)[source]

Read ascii data file.

Parameters
  • filename (str) – file to read

  • x_column (int) – column index for the x data (first column is 0)

  • y_column (int) – column index for the y data (first column is 0)

  • default (object) – return object if data loading fails

  • verbose (bool) – verbose information (default = False)

Returns

x and y

Return type

tuple(list, list)

seq(start, stop=None, step=1)[source]

Create an arithmetic bounded sequence.

The sequence is one of the following;

  • empty \(\{\}=\emptyset\), if start and stop are the same

  • degenerate \(\{a\}\), if the sequence has only one element.

  • left-close and right-open \([a, b)\)

Parameters
  • start (int or float) – start of the sequence, the lower bound. If only start is given than it is interpreted as stop and start will be 0.

  • stop (int or float) – stop of sequence, the upper bound.

  • step (int or float) – step size, the common difference (constant difference between consecutive terms).

Returns

arithmetic bounded sequence

Return type

list

store(file_name, object_data)[source]

Store program objects to binary file.

Parameters
  • file_name (str) – file to store

  • object_data (object) – data to store

unique_ending(ids, n=1)[source]

From id list get list with unique ending.

Parameters
  • ids (list) – ids

  • n (int) – minumum chars or ints

Returns

unique ending of ids

Return type

list

write(file_name, data)[source]

Write ascii file.

Parameters
  • file_name (str) – file to write

  • data (str) – data to write