TypeError: 'int' object is not callable whats is wrong?
TypeError: 'int' object is not callable whats is wrong?
你好,我目前正在为学校做一个小项目,任务是编写一个函数,它接受 dna 链和一个位置,并检查所选位置前后的 DNA 是否互补。
这是我到目前为止想出的代码。
翻译功能只是为了检查互补性,它工作得很好。
但是,如果我尝试将 DNA 提供给 lis 函数,则会出现错误。
File "xxx", line 37, in lis
while translate(dna[pos(1-i)],dna[pos(1+i)])=="TRUE":
TypeError: 'int' object is not callable
有人知道那里出了什么问题吗?
def translate(seq, comp):
#matchlist and checklist
basecomplement = {'A': 'T', 'C': 'G', 'G': 'C', 'T': 'A'}
baselist = ["A","T","G","C"]
#check wether the input is a DNA
if seq not in baselist:
print("FALSE")
elif comp not in baselist:
print("FALSE")
#check if the two (or more) bases are complements
else:
aaseq = []
comp = [comp]
for character in seq:
aaseq.append(basecomplement[character])
print(aaseq)
#print result
if aaseq == comp:
print("TRUE")
else:
print("FALSE")
def lis(dna, pos):
#make a list from DNA input
dna = [dna]
#go to pos in DNA list
for pos in range(len(dna)):
i=1
#check if position before and after pos are complements
#and advance a position if true else stop
while translate(dna[pos(1-i)],dna[pos(1+i)])=="TRUE":
i+=1
return(pos-i + pos+i)
break
这里有几件事要解决...
pos
是一个整数,而不是一个函数,所以 pos(1-i)
导致了你的 post 中的错误。这应该类似于 dna[pos-1]
和 dna[pos+1]
range
从 0 开始,所以 0-1
将是 -1
并且也会抛出超出范围的错误
translate()
不返回任何内容,仅打印。你需要return ("TRUE")
。您最好在此处使用布尔值 True
和 False
而不是字符串。
我没有看完你的整个片段,所以可能还有更多怪癖...
你好,我目前正在为学校做一个小项目,任务是编写一个函数,它接受 dna 链和一个位置,并检查所选位置前后的 DNA 是否互补。 这是我到目前为止想出的代码。 翻译功能只是为了检查互补性,它工作得很好。 但是,如果我尝试将 DNA 提供给 lis 函数,则会出现错误。
File "xxx", line 37, in lis
while translate(dna[pos(1-i)],dna[pos(1+i)])=="TRUE":
TypeError: 'int' object is not callable
有人知道那里出了什么问题吗?
def translate(seq, comp):
#matchlist and checklist
basecomplement = {'A': 'T', 'C': 'G', 'G': 'C', 'T': 'A'}
baselist = ["A","T","G","C"]
#check wether the input is a DNA
if seq not in baselist:
print("FALSE")
elif comp not in baselist:
print("FALSE")
#check if the two (or more) bases are complements
else:
aaseq = []
comp = [comp]
for character in seq:
aaseq.append(basecomplement[character])
print(aaseq)
#print result
if aaseq == comp:
print("TRUE")
else:
print("FALSE")
def lis(dna, pos):
#make a list from DNA input
dna = [dna]
#go to pos in DNA list
for pos in range(len(dna)):
i=1
#check if position before and after pos are complements
#and advance a position if true else stop
while translate(dna[pos(1-i)],dna[pos(1+i)])=="TRUE":
i+=1
return(pos-i + pos+i)
break
这里有几件事要解决...
pos
是一个整数,而不是一个函数,所以pos(1-i)
导致了你的 post 中的错误。这应该类似于dna[pos-1]
和dna[pos+1]
range
从 0 开始,所以0-1
将是-1
并且也会抛出超出范围的错误translate()
不返回任何内容,仅打印。你需要return ("TRUE")
。您最好在此处使用布尔值True
和False
而不是字符串。
我没有看完你的整个片段,所以可能还有更多怪癖...