readline() & seek() ???

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Wed Jun 4 18:25:41 EDT 2008


On Wed, 04 Jun 2008 14:30:19 -0700, DataSmash wrote:

> I have a text file that contains thousands of lines and each line is
> 256 characters long.
> 
> This is my task:
> For each line in the file, move to the 25th character, if the
> character is a "T",
> move to the 35th character of the line and read 5 characters from
> there.
> Capture these 5 characters and write them to a new text file, each 5
> characters separated by a comma.

No `readline()`, it's not a line based format but a record based one, and
no `seek()` because you don't need to access the records in random order.

Just use `read()` to read the 256 byte records one at a time and string
slicing to extract the data.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list