strseq

sisl.utils.strseq(cast, s, start=None, end=None)[source]

Accept a string and return the casted tuples of content based on ranges.

Parameters:
  • cast (function) – parser of the individual elements

  • s (str) – string with content

Examples

>>> strseq(int, "3")
3
>>> strseq(int, "3-6")
(3, 6)
>>> strseq(int, "-2")
-2
>>> strseq(int, "-2", end=7)
5
>>> strseq(int, "-2:2", end=7)
(-2, 2)
>>> strseq(int, "-2-2", end=7)
(-2, 2)
>>> strseq(int, "3-")
(3, None)
>>> strseq(int, "3:2:7")
(3, 2, 7)
>>> strseq(int, "3:2:", end=8)
(3, 2, 8)
>>> strseq(int, ":2:", start=2)
(2, 2, None)
>>> strseq(float, "3.2:6.3")
(3.2, 6.3)