neurotools.util.string module
- neurotools.util.string.hcat(*args, sep=' ', TABWIDTH=4, prefix='', suffix='')[source]
Horizontally concatenate two string objects that contain newlines
- neurotools.util.string.wordwrap(text, width=80, sep=' ')[source]
Wrap text to a fixed columnd width.
TODO: the implementation of this is a bit weird.
- Parameters:
words (list) – a list of words
width (positive int) – Width of column to wrap Optional, default is 80
sep (string) – Optional, default is ‘ ‘ Separator to join words by
- Returns:
lines – List of word-wrapped lines of text
- Return type:
list
- neurotools.util.string.incolumns(*args, prefix='', suffix='', sep=' ', width=80)[source]
Collate collection of strings into parallel columns
- neurotools.util.string.percent(n, total)[source]
Given n observations out of total, format n/total as a percentage to two decimal points
- Parameters:
n (int) – Number of positive samples
total (int) – Size of population
- Return type:
str
- neurotools.util.string.shortscientific(p, prec=0, latex=False, sigthr=None)[source]
Shortest viable string formatting for scientific notation.
- Parameters:
x (float)
prec (non-negative integer; default 0) – Extra decimals to add. Value of 0 uses only one significant figure.
latex (boolean; defaultFalse) – Whether to prepare string for latex rendering
- Return type:
str
- neurotools.util.string.eformat(f, prec, exp_digits)[source]
Format a float in scientific notation with fewer characters.
- Parameters:
f (scalar) – Number
prec – Precision
exp_digits (int) – Number exponent digits
- Returns:
Formatted string
- Return type:
str
- neurotools.util.string.v2str(p, sep=',')[source]
Format list of numbers as string in short scientific notation. (see shortscientific())
- Parameters:
p (iterable of floats) – Numbers to format
sep (str) – Item separtor
- Return type:
str
- neurotools.util.string.v2str_long(p, sep=',')[source]
Format list as string with maximum precision.
- Parameters:
p (iterable of floats) – Numbers to format
sep (str) – Item separtor
- Return type:
str
- neurotools.util.string.nicetable(data, format='%4.4f', ncols=8, prefix='', sep=' ')[source]
Format a numeric vector as an evenly-spaced table
- neurotools.util.string.isInt(v)[source]
Check if a string is an integer
stackoverflow.com/questions/1265665/python-check-if-a-string-represents-an-int-without-using-try-except
- Parameters:
v (str)
- Return type:
boolean