[Tutor] text processing lines variable content

ingo janssen ingoogni at gmail.com
Thu Feb 7 14:50:34 EST 2019


On 07/02/2019 18:06, Peter Otten wrote:
> Sorry, I don't understand the question.

after a quick look not unlike what you propose but I have to investigate 
further,

lengths of chunks are known or can be found (sketchy):

order= [%i,%q,%r,%w,%p,%P,%o,%m,%g,%E,%s,%e,%F,%a,%A,%f,%t,%l,%n,%v,%c,%C]
length=[ 1, 3, 1, 1,%w,%w,%w, 1, 1, 1, 1,%s, 1,%s,%a,%s,%s,%s,%s, 1, 3, 3]

from there calculate the slices per line
slices={"%i":(0,1), "%q":(1,4), "%r":(4:5)....etc

modify all functions to accept and deal with the slice tuple, then the 
action loop gets very simple:

for points, line in enumerate(open("vorodat.txt.vol",'r'), 1):
   line = line.strip()
   line = line.split(" ")
   slices = calculate_slices(line)
   function[action](content[action],slices[action])

thanks for your time and insight, I'll try a few different ways

ingo


More information about the Tutor mailing list