CSC111 listmyprogram utility

From dftwiki3
Revision as of 09:41, 1 March 2010 by Thiebaut (talk | contribs)
Jump to: navigation, search

--D. Thiebaut 14:41, 1 March 2010 (UTC)


Utility to list python programs (or text files) the same way they will be listed on printouts. Useful for spotting lines that are too long and that will be wrapped around on the listing.

.

#! /usr/bin/python
# D. Thiebaut
# Utility to list python programs (or text files) the same way
# they will be listed on printouts.  Useful for spotting lines that 
# are too long and that will be wrapped around on the listing.
# Usage:
#      listmyprogram programname.py
#
import textwrap
import sys

if len( sys.argv ) < 2:
    print "\nSyntax %s programname\n\n" % sys.argv[0]
    sys.exit( 1 )

text = open( sys.argv[1], "r" ).read()
lines = text.split( "\n" )
for line in lines:
    if len( line ) >= 86:
        print line[:86]+"\n"+line[86:]
    else:
        print line

.