[Tutor] collecting certain data from a textfile

2009-09-15 Thread Olli Virta
Hi!

I got this simple but effective piece of code. It picks certain wanted
pieces of data from a textfile based on database records and puts all of
them them in a new textfile in certain order. I was wondering, could it be
possible to make it otherwise in case that there's much more rows in that
textfile and/or there's much more bits of data to collect?

data = open('data.txt','r')
f1 = data.readlines()
data.close()
f2 = open('data.txt','r')
i=0
f3 = []
while i  len(f1):
   a=f2.readline()
   b=f2.readline()
   c=f2.readline()
   data2 = (
a[1:38].strip()+';'+
a[54:88].strip()+';'+
b[77:96].strip()+';'+
b[1:16].strip()+';'+
c[23:33].strip()+';'+
c[123:133].strip()+';'
)
   wanted = (data2)
   f3.append(wanted + \n)
   i += 3
f4 = open('wanted.txt', 'w')
f4.write(''.join(f3))
f2.close()
f4.close()
Thanks! OV
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] handling a textfile continued

2009-08-20 Thread Olli Virta
Hi!

Sorry. OK I admit I might have been confusing. Although I got some good
ideas from the messages. Thanks.

Let me try again:

So I got this big textfile. It's full of data from a database. About 200 or
more rows or lines in a textfile.
There's three first rows that belong to the same subject. And then next
three rows belong to another subject and so on, to the end of the file.

What I need to do, is put the three rows that goes together and belong to
certain subject, on a one single line in the output textfile.
And that goes with the rest of the data to the end of the new file.

Thanks. OV
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] handling a textfile

2009-08-19 Thread Olli Virta
Hi!

I have a textfile (job.txt) that needs modifying. The structure of this file
is like this:

AAA1...
BBB1...
CCC1...
AAA2...
BBB2...
CCC2...
etc...



Question is how can I turn this all to a textfile (done.txt) that is suppose
to look like this:

AAA1...BBB1...CCC1...
AAA2...BBB2...CCC2...
etc.

Thanks! OV
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor