[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Sheflug] Extracing data from a file



On Tuesday 16 Apr 2002 6:15 pm, you wrote:

> Are the records seperated by a blank line, or anything similar?
> What does the id_string look like? Letters, letters and numbers, a
> particular combination?

I imagine he means a literal "id_string" and then 'i' is the id string.

Probably.

So you do this in Python:

#!/usr/bin/python
# If this works I would be incredibly suprised

import string

class Record:
	def __init__(self, name):
		self.name = name
		self.size = 0
		self.data = []
	def write(self):
		outfile = open(self.name)
		for i in range(0. self.size):
			outfile.write(self.data[i])
			outfile.write("\n")

infile = open("input")

line = infile.readline()
record = None

while (line):
	if line == "id_string":
		if record != None:
			record.write()
		record = None
	elif record == None:
		record = Record(line)
	elif record.size == 0:
		record.size == string.atoi(line)
		for i in range(0, record.size):
			record.data[i] = infile.readline()
			
	
___________________________________________________________________

Sheffield Linux User's Group -
http://www.sheflug.co.uk/mailfaq.html

  GNU the choice of a complete generation.