说明
length = 2
s = '1234567'
# target: ['12', '34', '56', '7']
length = 3
s = '1234567'
# target: ['123', '456', '7']
方法
# 方法1
import textwrap
textwrap.fill(s, length).split()
# 方法2
[s[i:i+2] for i in range(0, len(s), length)]
# 方法3
import re
[x for x in re.split(r'(.{%d})' % length, s) if x]
[x for x in re.split(rf'(.{{{length}}})', s) if x]
# 方法4
from functools import partial
from io import StringIO
[x for x in iter(partial(StringIO(s).read, length), '')]