This snippet shows a fast and efficient way to cut strings in substrings with a fixed length (note that the last substring may be smaller).
Cutting a string in equal pieces
import re
split5 = re.compile(r".{1,5}", re.DOTALL).findall
if __name__ == "__main__":
print split5('"Give me bacon and eggs," said the other man.')
# prints ['"Give', ' me b', 'acon ', 'and e', 'ggs,"', ' said', ' the ', 'other', ' man.']
Gribouillis 1,391 Programming Explorer Team Colleague
Gribouillis 1,391 Programming Explorer Team Colleague
lrh9 95 Posting Whiz in Training
bumsfeld 413 Nearly a Posting Virtuoso
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.