Insert a newline character every 64 characters using Python

后端 未结 7 2150
無奈伤痛
無奈伤痛 2020-12-01 17:46

Using Python I need to insert a newline character into a string every 64 characters. In Perl it\'s easy:

s/(.{64})/$1\\n/

How could this be

7条回答
  •  渐次进展
    2020-12-01 18:34

    I'd go with:

    import textwrap
    s = "0123456789"*100
    print '\n'.join(textwrap.wrap(s, 64))
    

提交回复
热议问题