2014-02-23 52 views
1

所以我有一组文件,我需要从一个新的txt文件中提取数据并写入,并且我不知道如何使用Python执行此操作。以下是一个示例数据。我正在尝试从NSF组织,文件和摘要中提取部分。如何从文本文件中提取数据?

标题:CRB: 线粒体DNA和历史人口学 类型:Mysticete鲸鱼的濒危种群遗传多样性奖 NSF组织:DEB 最新 修订 日期:1991年8月1日
文件:a9000006

奖号:9000006 原音乐奖:授予继续
PRGM经理:斯科特·柯林斯
DEB DIVISION环境科学的 直接BIO生物科学
开始日期:1990年6月1日
截止日期:1992年11月30日,(估计) 预计 总金额。 :$一十七万九千七百二十零(估计) 研究员:斯蒂芬R. Palumbi(首席研究员电流) 主办单位:夏威夷马诺阿 2530多尔街 檀香山的U,HI 968222225 808/956-7800

NSF计划:1127系统学&人口BIOLO FLD Applictn: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. 

回答

0

你并没有给我太多的东西,但是,我做什么来从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) 
+0

您能否提供Python代码吗? –

+0

感谢您的回复。我很新,试图弄清楚这段代码,但对time_list []行感到困惑。你能解释一下吗?非常感谢。 –

+0

嗯,这是我从txt文件中读取时间的代码。 time_list只是一个数组 – KRUKUSA

相关问题