string - Python Insert new line if line has more than 50 characters -
i've been trying figure out issue on python that's driving me crazy couple of weeks... have text file decent amount of text. of lines has more 50 characters , issue me, because has aligned text box.
my question : how manage insert new line (\n) if line on text file has more 50 characters (including spaces)?
thanks in advance.
this should trick
with open('path/to/input') infile, open('path/to/output', 'w') outfile: line in infile: if len(line) > 50: outfile.write('\n'.join(line[i:i+50] in xrange(0,len(line), 50))) else: outfile.write(line)
Comments
Post a Comment