我是python的初学者。我需要从txt文件到新文件中,从traits列中拉出显示癌症患者的行。每 该行包含四列:SNP标识符,定位基因,报告的性状和 位置。我编写的代码有误,因为它无法读取特征,如何复制到新文件中?
import re
def readdata(dname):
try:
my_file= open(dname, 'r')
fields=my_file.split(",")
traits= fields.readlines()
for Reported traits in traits:
if traits = cancer:
cancer = input("Enter the type = ")
record = my file.read()
answer = record.find(cancer)
for line in answer:
print(line)
elif:
break