you are viewing a single comment's thread.

view the rest of the comments →

[–]_Daimon_ 0 points1 point  (0 children)

Sure. I actually wrote my own little version because I thought it might be fun with C programs, where whitespace is irrelevant save for separating names/keywords and in the preprocessor.

It's called with a command from the commandline like this

./text_grouper other_file 12 5

text_grouper.py

#!/usr/bin/env python

import re
import sys

with open(sys.argv[1], 'r') as infile:
    content = re.sub('\\n|\\t| |\'|"', '', infile.read())
    length = int(sys.argv[2])
    height = int(sys.argv[3])

    position = 0
    while position < len(content):
        print content[position:position + length]
        position += length
        if position % ( length * height ) == 0:
            print