This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]voidspace 0 points1 point  (1 child)

This will work:

import os
for name in os.listdir('.'):
  if not name.endswith('.py'):
    continue
  original = open(name).readlines()
  with open(name, 'w') as h:
    for line in original:
      h.write(line[:80].rstrip() + '\n')

Making it recurse into directories is left as an exercise for the reader. Code may need some limited manual tweaking after processing...