从txt文件中提取特定行并将其保存在新文件中

时间:2019-05-07 09:16:33

标签: python file jupyter-notebook

我是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

0 个答案:

没有答案