Python 如何从文本文件中提取数据?

Python 如何从文本文件中提取数据?,python,Python,所以我有一组文件,我需要从中提取数据并写入一个新的txt文件,我不知道如何使用Python实现这一点。下面是一个示例数据。我试图从NSF组织、文件和摘要中提取这些部分 标题:CRB:濒危鲸鱼种群的遗传多样性: 线粒体DNA与历史人口学 类型:奖励 NSF组织:DEB 最近的 修正案 日期:1991年8月1日 档案:a9000006 奖项编号:9000006 奖励说明:持续补助金 公关经理:斯科特·柯林斯 环境生物学系 生物科学的生物指导 开始日期:1990年6月1日 有效期:1992年11月30

所以我有一组文件,我需要从中提取数据并写入一个新的txt文件,我不知道如何使用Python实现这一点。下面是一个示例数据。我试图从NSF组织、文件和摘要中提取这些部分

标题:CRB:濒危鲸鱼种群的遗传多样性: 线粒体DNA与历史人口学 类型:奖励 NSF组织:DEB 最近的 修正案 日期:1991年8月1日 档案:a9000006

奖项编号:9000006 奖励说明:持续补助金 公关经理:斯科特·柯林斯 环境生物学系 生物科学的生物指导 开始日期:1990年6月1日 有效期:1992年11月30日 预期 总金额:$估计179720 调查员:斯蒂芬·帕伦比现任首席调查员 赞助商:夏威夷大学马诺亚分校 多尔街2530号 檀香山,HI 968222225808/956-7800

NSF项目:1127系统与人口生物学 Fld应用:0000099其他应用NEC 61生命科学生物学 项目编号:9285, 摘要:

          Commercial exploitation over the past two hundred years drove the great    
          Mysticete whales to near extinction.  Variation in the sizes of populations  
          prior to exploitation, minimalpopulation size during exploitation and 
          current population sizes permit analyses of the effects of differing levels 
          of exploitation on species with different biogeographical distributions and 
          life-history characteristics. 

你们并没有给我太多的东西,但是,我要做的是从txt文件中读取输入文件。这是用Java编写的,希望您知道如何将其存储在某种数组中

import java.util.Scanner;

import java.io.*;

public class ClockAngles{

public static void main (String [] args) throws IOException {

Scanner reader = null;
String input = "";
try {
    reader = new Scanner (new BufferedReader (new FileReader("FilePath")));

    while (reader.hasNext()) {
        input = reader.next();
        System.out.print(input);

    } 
}

finally {
        if (reader != null) {
        reader.close();
        }
}
Python代码

#!/bin/env python2.7

# Change this to the file with the time input
filename = "filetext"

storeData = []

class Whatever:
def __init__(self, time_str):
    times_list = time_str.split('however you want input to be read')
    self.a = int(times_list[0]) 
    self.b = int(times_list[1]) 
    self.c = int(times_list[2]) 
    # prints the data
    def __str__(self):
    return str(self.a) + " " + str(self.b) + " " + str(self.c)

谢谢你的回复。我是一个新手,试图找出这段代码,但对时间列表[]行感到困惑。你能解释一下吗?非常感谢。这是我从txt文件中读取时间的代码。时间列表只是一个数组