【发布时间】:2021-03-02 09:03:58
【问题描述】:
我一直收到这个错误,谁能帮我解决这个问题?我在下面突出显示了有问题的代码行。我尝试将 reader 变量更改为 reader1,但问题仍然存在。
错误信息
Traceback(最近一次通话最后一次):
文件“dna.py”,第 20 行,在
读者 = 读者(人物档案)
TypeError: '_csv.reader' 对象不可调用
**
- 我的代码
**
from sys import argv
from csv import reader, DictReader
if len(argv) < 3:
print("Wrong number of arguments")
exit()
#read the database file into memory
with open(argv[2]) as file:
reader = reader(file)
for row in reader:
dnalist = row
#create a variable containing the sample DNA
dna = dnalist[0]
#create a dictionary that holds the STR and the highest rep count
sequences = {}
with open(argv[1]) as peoplefile:
reader = reader(peoplefile) **<------ ERROR IS HERE**
for row in reader:
dnasequences = row
dnasequences.pop(0)
break
#set the STRs as keys in sequences dictionary
for i in dnasequences:
sequences[i] = 1
#Obtain the highest number of reps of each STR in the given DNA sequence
for key in sequences:
l = len(i)
tmp = 0
tmpmax = 0
#check
for i in dna:
if dna[i: i + l] == key:
tmp = 1
while dna[i:i+l] == dna[ i+l : i+2*l ]:
tmp += 1
i += l
if tmp > tmpmax:
tmpmax = tmp
sequences[key] = tmpmax
#Read database file into a dictionary
with open(argv[1]) as peoplefile:
reader = DictReader(peoplefile)
#loop through STR counts, comparing it to each person's STR counts
for person in reader:
match = 0
for i in sequences:
if sequences[i] == int(person(i)):
match += 1
#if all the highest STR reps match the person, print that person's name
if match == len(sequences):
print(row['name'])
exit()
print("Does not match any person")
【问题讨论】: