【发布时间】:2012-05-06 06:31:01
【问题描述】:
除了已经在代码中的那些之外,我还尝试使用 newString.strip('\n') ,但它没有做任何事情。我正在输入一个不应该有问题的 .fasta 文件。提前致谢。
def createLists(fil3):
f = open(fil3, "r")
text = f.read()
listOfSpecies = []
listOfSequences = []
i = 0
check = 0
while (check != -1):
startIndex = text.find(">",i)
endIndex = text.find("\n",i)
listOfSpecies.append(text[startIndex+1:endIndex])
if(text.find(">",endIndex) != -1):
i = text.find(">",endIndex)
newString = text[endIndex+1: i]
newString.strip()
newString.splitlines()
listOfSequences.append(newString)
else:
newString = text[endIndex+1:]
newString.strip()
newString.strip('\n')
listOfSequences.append(newString)
return (listOfSpecies,listOfSequences)
def cluster(fil3):
print createLists(fil3)
cluster("ProteinSequencesAligned.fasta")
【问题讨论】:
-
只遍历文件有什么问题?
-
在剥离调试之前尝试添加一个 print newString
-
我有,脱衣前后没有区别,我觉得很奇怪
-
尝试在 strip 前后打印 repr(newString),如果在 strip 之前没有显示 \n 则字符串永远不会有换行符
-
两者都有新字符串。这是 fasta 文件的样子