snpl.util module

Utility functions

snpl.util.attach_postfix(fpath, postfix)[source]
snpl.util.attach_prefix(fpath, prefix)[source]
snpl.util.datetime2epochsecond(dt)[source]
snpl.util.epochsecond2datetime(es)[source]
snpl.util.modify_path(d, ext=None, pref=None, postf=None)[source]
snpl.util.natural_sort(li, key=<function <lambda>>)[source]

Sorts the list into natural alphanumeric order.

Performs an inplace natural sort on a list of strings.

Parameters:
  • li (list) – List to be sorted.

  • key (callable) – Function that takes a single argument and returns a key to be used for sorting. Defaults to lambda s:s (the argument is used as the key).

Returns:

None

Examples

>>> a = ["f2", "f0", "f10", "f1"]
>>> a.sort()
>>> print(a)
['f0', 'f1', 'f10', 'f2']
>>> natural_sort(a)
>>> print(a)
['f0', 'f1', 'f2', 'f10']
snpl.util.splitnull(c_string)[source]

convert null terminated string to a string

snpl.util.swap_ext(fpath, new_ext)[source]