On 7/09/25 00:47, Rob Cliffe via Python-list wrote:
I quite often find myself writing expressions of the form
     someString[x : x+n]
where n is often an int and x may be an int, a variable, or a (possibly complicated) expression.


0 A PEP

1 A helper-function
eg slice_by_length( input_string, start, length, )

2 Slice as an Object
run_length_slice = slice( start_index, start_index + slice_length, )
...
substring = source_string[ run_length_slice ]

3 Custom Class
with behavior similar to (1)

4 Pydantic
similar to above


Which might be best will vary by circumstance - YMMV!

--
Regards,
=dn

--
https://mail.python.org/mailman3//lists/python-list.python.org

Reply via email to