Instructions for filesTest

(produced at 10:21 a.m. UTC on 2021-11-04)

This task is part of test which is due at 23:59 EST on 2022-01-01.

This is an individual task.

Put all of your work for this task into the file files.py
(you will create this file from scratch)

This task involves writing three functions: listFile, grep, and addRecords.

  • listFile prints each line of a target file, along with line numbers.
  • grep reads lines from one file, finds those that contain a certain string fragment, and then writes those to a second file.
  • addRecords appends lines to a file based on a list of strings, adding a newline character to the end of each string as it writes into the file so that they appear as different lines.

Note that these tests do not clean up created files, as it's assumed that the entire sandbox will be cleaned up at some point.

Examples

listFile examples

These examples show how listFile should work on the birds and fish lists provided with the starter code.

In []:
listFile('birds.txt')
Prints
1 tern 2 albatross 3 seagull 4 sparrow 5 cardinal 6 oriole 7 robin 8 swallow 9 stork 10 cassowary 11 ostrich 12 chicken 13 tanager 14 goose 15 turkey 16 quail 17 chickadee 18 nuthatch
In []:
listFile('fish.txt')
Prints
1 tuna 2 swordfish 3 sawfish 4 sunfish 5 mackerel 6 anchovy 7 flying fish 8 angler fish 9 lantern fish 10 salmon 11 carp 12 catfish

grep examples

These examples show how grep should work on the birds and fish lists provided with the starter code.

In []:
grep('birds.txt', 'er', 'birds.txt.er')
File
birds.txt.er
tern tanager
In []:
grep('fish.txt', 'er', 'fish.txt.er')
File
fish.txt.er
mackerel angler fish lantern fish
In []:
grep('dir/mammals.txt', 'er', 'dir/mammals.txt.er')
File
dir/mammals.txt.er
panther

Rubric

 
unknown Product Requirements
Your code's result values.
 
unknown Core goals
Complete all core goals for core credit. Get partial credit for completing at least half, and more partial credit for completing at least 90%.
 
unknown grep returns the correct result
The result returned when your grep function is run must match the solution result.
 
unknown Behavior Requirements
What your code does from the user's perspective.
 
unknown Core goals
Complete all core goals for core credit. Get partial credit for completing at least half, and more partial credit for completing at least 90%.
 
unknown listFile prints the correct output
The output printed when your listFile function is run must match the solution output.
 
unknown Extra goals
Complete all extra goals in addition to the core goals for a perfect score.
 
unknown addRecords writes the correct data into records.txt
The data written to records.txt when your addRecords function is run must match what the solution writes.