Skip to content
Advertisement

How can I print a single row element in Python DictReader

I’ve got a program to find DNA matches. We’ve been given a one line text file for finding the longest sequence of STR(Short Tandem Repeats) then match the result with a database which has been a .cvs file as below:

JavaScript

After getting results for longest sequence amounts(as integer) I’m trying to find a match in this cvs file and print the value in the first column (name) when I found the matching numbers of STR. I’m checking the program with print() and it prints ‘no match’ until the matched name then stops with below error code:

JavaScript

My program probably finds the match but can’t print out than exits. Could you please help me? TIA

JavaScript

Advertisement

Answer

I used the data you provided and made a test.csv

JavaScript

Then tested with the folowing code (py csv-test.py test.csv):

JavaScript

And the result was “Albus”.

PS. With:

JavaScript

I get the same KeyError as you do.

Do I miss something?

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement