Please send questions to
st10@humboldt.edu .
#! /usr/bin/python
'''
lect07.py
contains examples of functions making use of file input/output
'''
# by: Sharon Tuttle
# last modified: 10-17-06
# assumes that hw4.py is in the same directory as lect07py...!
# (or in the sys.path...)
import hw4
def pig_latin_file(input_name, output_name):
'''
write pig-latin versions of all the lines of file <input_name>
into file <output_name> - nukes any previous contents of
<output_name>!
'''
input_file = open(input_name, 'r')
output_file = open(output_name, 'w')
# pig-latinize each line from input_file
next_line = input_file.readline()
while next_line != "":
next_pig_line = hw4.pig_string(next_line)
# (pig_string removes the newline at end of line...)
output_file.write(next_pig_line + '\n')
next_line = input_file.readline()
input_file.close()
output_file.close()
# assumes that hw5.py is in the same directory as lect07py...!
# (or in the sys.path...)
import hw5
def letter_freq_file(input_name):
'''
shows to the screen a simple ASCII horizontal "bar chart" of
all of the letters within file <input_name>
'''
input_file = open(input_name, 'r')
# read entire file into a string?!
input_string = input_file.read()
hw5.show_counts( hw5.letter_freq(input_string) )