Difference between revisions of "CSC111 listmyprogram utility"
(Created page with '--~~~~ ---- 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 a…') |
|||
Line 31: | Line 31: | ||
. | . | ||
</source> | </source> | ||
+ | |||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | [[Category:CSC111]][[Category:Python]] |
Revision as of 09:41, 1 March 2010
--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
.