所以我有一组文件,我需要从其中提取数据并写入到一个新的txt文件中,但我不确定如何使用Python来做到这一点。下面是一个示例数据。我正在尝试从NSF组织,文件和摘要中提取部分。
标题: CRB:濒临灭绝的神秘鲸鱼种群的遗传多样性:线粒体DNA和历史人口学类型:获奖NSF组织: DEB最新修订日期:1991年8月1日
文件: a9000006
奖励编号: 9000006奖励实例:继续发放
Prgm经理:斯科特·柯林斯
DEB DIVISION OF ENVIRONMENTAL BIOLOGY
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
61 Life Science Biological
程序编号: 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.
发布于 2014-02-23 14:48:03
你没有给我太多的东西,但是,我要做的是从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)
https://stackoverflow.com/questions/21965099
复制相似问题