sisl.utils.ranges module¶
Basic functionality of creating ranges from text-input and/or other types of information
-
sisl.utils.ranges.
strmap
(func, s, sep='b')[source]¶ Parse a string as though it was a slice and map all entries using
func
.Parameters: func : function
function to parse every match with
s :
str
the string that should be parsed
sep :
str
('b'
,'c'
,'*'
/'s'
)optional separator used,
'b'
is square brackets,'c'
, curly braces, and'*'
/'s'
is the starExamples
>>> strmap('1') [func('1')] >>> strmap('1-2') [func('1-2')] >>> strmap('1-10[2-3]') [( func('1-10'), func('2-3'))]
-
sisl.utils.ranges.
strseq
(cast, s)[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
>>> strmap(int, '3') 3 >>> strmap(int, '3-6') (3, 6) >>> strmap(int, '3:2:7') (3, 2, 7) >>> strmap(float, '3.2:6.3') (3.2, 6.3)
-
sisl.utils.ranges.
lstranges
(lst, cast=<function erange>)[source]¶ Convert a
strmap
list into expanded ranges
-
sisl.utils.ranges.
list2range
(lst)[source]¶ Convert a list of elements into a string of ranges
Examples
>>> list2range([2, 4, 5, 6]) 2, 4-6 >>> list2range([2, 4, 5, 6, 8, 9]) 2, 4-6, 8-9
-
sisl.utils.ranges.
fileindex
(f, cast=<type 'int'>)[source]¶ Parses a filename string into the filename and the indices.
- This range can be formatted like this:
- file[1,2,3-6]
- in which case it will return:
- file, [1,2,3,4,5,6]
Parameters: f :
str
filename to parse
cast : function
the function to cast the bracketed value