textwrap.wrap(text,[width[,…]])
import textwrap sample_text = '''aaabbbcccdddeeeedddddfffffggggghhhhhhkkkkkkk''' sample_text2 = '''aaa bbb ccc ddd eeee ddddd fffff ggggg hhhhhh kkkkkkk''' print(sample_text) print(textwrap.wrap(sample_text,width=5)) print(textwrap.wrap(sample_text2,width=5))