Assignment 3
Due: 11:00 AM on Friday, October 3, 2008
Question #1
Consider the following advanced version of the file-format checking
script described in Question #1 of Assignment #2: Instead of
two command-line arguments (the name of an integer-file and a
file-format specification string (ffs)), take between one and
four command-line arguments where the first argument is the
name of the integer-file and the remaining arguments are drawn
from the following set and may appear in any order:
- "-rNR": specifies that the number of rows (lines) in the integer-file
must be NR, where NR is a non-zero positive integer.
- "-cNC": specifies that the number of columns in the integer-file
must be NC, where NC is a non-zero positive integer.
- "-sFFS": specifies that each row must be formatted according ffs FFS.
No argument from this set is repeated. In addition
to all error-messages output by the original script, appropriate
error messages are also output for (i) unrecognized command-line
arguments that begin with a "-" but do not have "r", "c", or "s" as
a second symbol, (ii) invalid command line arguments, i.e.,
those not beginning with "-", (iii) conflicting command-line
arguments, i.e., len(ffs) != NC (in this case, the "-cNC"
argument is ignored), (iv) lines having the
wrong number of columns, and (v) files having the incorrect
number of rows.
Write and document a Python script ffc2.py implementing
the file-format checker described above.
Your script must work on datafiles
ffc2a.dat and
ffc2b.dat
to produce the output given in typescript-file
ffc2.script.
You may assume that all given files have at least one row, all row- and
column-numbers specified b y "-r" and "-c" command-line arguments are valid,
and all ffs specified by "-s" command-line arguments are valid.
Question #2
Write and document a Python script anon1.py which takes as
command-line arguments a text file named X and a file of single-word (possibly
hyphenated) proper
names (one per line), and creates the file named "X.anon" in which each occurrence
of a specified proper name is replaced by the string "AY", where string "Y" is
the line-number of that name in the name-file right-justified in an initial
zero-filled field of length 5. The textfile consist of letters, numbers,
spaces, the period, comma, left and right parenthesis, and apostrophe
punctuation marks and proper-name internal hyphens, and each line in the file begins and ends
with a space.
An occurrence of a proper name is any string equal to that name that is
surrounded by spaces or punctuation marks.
Your script must work on datafiles
text1.dat,
name1.dat, and
name2.dat
to produce the output given in typescript-file
anon1.script.
You may assume that all text and name files are valid.
Hints
You may find the various example scripts in the course notes of use.
In Question #1, you may find it useful to modify the script written
(either by you or the course instructor) for Question #1 of
Assignment #2. You may also find the continue-statement even more
useful this time in organizing your control-structures.
In Question #2, you may find it useful to replace all punctuation marks
and spaces in a file with special strings before anonymizing names and
then reversing the replacement of the special strings to reconstruct
the punctuation marks and spaces.
Submission
Please hand in printed copies of all of your Python script files.
You must also submit these files electronically using the
submit-assignment command.
Note that each script file must have the following comment
block at the top, where the X's are replaced with the appropriate
information, followed by a docstring briefly describing the program in that
script. For instance, my script for Question #1 of this assignment would
begin with the following comment block:
#########################################################
## CS 2500 (Fall 2008), Assignment #3, Question #1 ##
## Script File Name: ffc2.py ##
## Student Name: Todd Wareham ##
## Login Name: harold ##
## MUN #: 8008765 ##
#########################################################
If you choose to base your script on any answer-scripts for previous
assignments, please note this in the docstring.
You do not have to develop your code on our CS departmental systems.
However, as your code will be compiled and tested on our CS departmental
systems as part of the assignment marking process,
you should ensure that your code compiles and runs correctly on at
least one of these systems.
- Sep 22, 1:50pm
Assignment #3 posted.
Created: September 22, 2008
Last Modified: September 22, 2008