CSC111 listmyprogram utility
--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 sys
# check command line parameters
if len( sys.argv ) < 2:
print "\nSyntax %s programname\n\n" % sys.argv[0]
sys.exit( 1 )
# open file
text = open( sys.argv[1], "r" ).read()
# split it into lines, and print each one, splitting it in half if
# longer than 86 chars
lines = text.split( "\n" )
for line in lines:
if len( line ) >= 86:
print line[:86]+"\n"+line[86:]
else:
print line
.