Reading by positions plain text files

MRAB python at mrabarnett.plus.com
Tue Nov 30 18:36:49 EST 2010


On 30/11/2010 21:31, javivd wrote:
> 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?
>
It sounds like a similar problem to this:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/53ebbbb6f41bfff6/123422d510187dc3?show_docid=123422d510187dc3



More information about the Python-list mailing list