Skip to content

Added error handling to file reading; fixes #3 #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions caduceus/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,25 @@ def build_snakes(common_file, sci_file):
Returns: an unsorted list of Snake items
'''
snakes = []
# that above may be the docstring?

with open(common_file, 'rb') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
s = Snake(0, 0, row["common name"], row["scientific name"])
snakes.append(s)
try:
with open(common_file, 'rb') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
s = Snake(0, 0, row["common name"], row["scientific name"])
snakes.append(s)

for snake in snakes:
with open(sci_file, 'rb') as csvfile2:
reader2 = csv.DictReader(csvfile2)
for row in reader2:
if snake.sci_name == row['scientific name']:
snake.weight = int(row["weight"])
snake.length = int(row['length'])
for snake in snakes:
with open(sci_file, 'rb') as csvfile2:
reader2 = csv.DictReader(csvfile2)
for row in reader2:
if snake.sci_name == row['scientific name']:
snake.weight = int(row["weight"])
snake.length = int(row['length'])

except: #I don't know what sort of error it would be
print "Cadeceus expects specific columns in csv files to work. See help(build_snakes)."

return snakes

Expand Down