首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何从文本文件中提取数据?

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

Stack Overflow用户
提问于 2014-02-23 14:43:18
回答 1查看 693关注 0票数 1

所以我有一组文件,我需要从其中提取数据并写入到一个新的txt文件中,但我不确定如何使用Python来做到这一点。下面是一个示例数据。我正在尝试从NSF组织,文件和摘要中提取部分。

标题: CRB:濒临灭绝的神秘鲸鱼种群的遗传多样性:线粒体DNA和历史人口学类型:获奖NSF组织: DEB最新修订日期:1991年8月1日

文件: a9000006

奖励编号: 9000006奖励实例:继续发放

Prgm经理:斯科特·柯林斯

代码语言:javascript
运行
复制
       DEB  DIVISION OF ENVIRONMENTAL BIOLOGY
代码语言:javascript
运行
复制
       BIO  DIRECT FOR BIOLOGICAL SCIENCES

开始日期:1990年6月1日

到期时间: 1992年11月30日(预估)预期总金额:$179720 (预估)调查员: Stephen R. Palumbi (首席调查员,现任)赞助商:夏威夷大学Manoa2530Dole Street Honolulu,HI 968222225

NSF计划:1127Systemed& POPULATION BIOLO Fld Applictn: 0000099 Other Applications NEC

代码语言:javascript
运行
复制
           61        Life Science Biological

程序编号: 9285,摘要:

代码语言:javascript
运行
复制
          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. 
EN

回答 1

Stack Overflow用户

发布于 2014-02-23 14:48:03

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

代码语言:javascript
运行
复制
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代码

代码语言:javascript
运行
复制
#!/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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21965099

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档