Reading by positions plain text files

javivd javiervandam at gmail.com
Tue Nov 30 22:31:26 CET 2010


Hi all,

Sorry, newbie question:

I have database in a plain text file (could be .txt or .dat, it's the
same) that I need to read in python in order to do some data
validation. In other files I read this kind of files with the split()
method, reading line by line. But split() relies on a separator
character (I think... all I know is that it's work OK).

I have a case now in wich another file has been provided (besides the
database) that tells me in wich column of the file is every variable,
because there isn't any blank or tab character that separates the
variables, they are stick together. This second file specify the
variable name and his position:


VARIABLE NAME	POSITION (COLUMN) IN FILE
var_name_1 		123-123
var_name_2 		124-125
var_name_3 		126-126
..
..
var_name_N 		512-513 (last positions)

How can I read this so each position in the file it's associated with
each variable name?

Thanks a lot!!

Javier




More information about the Python-list mailing list