Skip to content

Instantly share code, notes, and snippets.

@chrismo
Created November 18, 2014 05:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismo/47030cd4c07a4cc7f6d4 to your computer and use it in GitHub Desktop.
Save chrismo/47030cd4c07a4cc7f6d4 to your computer and use it in GitHub Desktop.
Coloured fox fur production, HOPEDALE, Labrador, 1834-1842
#Source: C. Elton (1942) "Voles, Mice and Lemmings", Oxford Univ. Press
#Table 17, p.265--266
29
22
2
16
12
35
8
83
166
import time_series
def smallest_value(reader):
""" (file open for reading) -> NoneType
Read and process reader and return the smallest value after the
time_series header.
"""
line = time_series.skip_header(reader).strip()
# Now line contains the first data value; this is also the smallest value # found so far, because it is the only one we have seen.
smallest = int(line)
for line in reader:
value = int(line.strip())
# If we find a smaller value, remember it.
if value < smallest: smallest = value
return smallest
if __name__ == '__main__':
with open('hopedale.txt', 'r') as input_file:
print(smallest_value(input_file))
def skip_header(reader):
""" (file open for reading) -> str
Skip the header in reader and return the first real piece of data.
"""
# Read the description line
line = reader.readline()
# Find the first non-comment line
line = reader.readline()
while line.startswith('#'):
line = reader.readline()
# Now line contains the first real piece of data
return line
def process_file(reader):
""" (file open for reading) -> NoneType
Read and print the data from reader, which must start with a single description line, then a sequence of lines beginning with '#', then a sequence of data.
"""
# Find and print the first piece of data
line = skip_header(reader).strip()
print(line)
# Read the rest of the data
for line in reader:
line = line.strip()
print(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment