2011/1/25 Alex Brollo <alex.brollo(a)gmail.com>
Just to test effectiveness of such a strange idea, I added some formal
section tags into a 6 Kby text section.txt, then I wrote a simple script to
create a "data area" , this is the result (a python dictionary into a html
comment code) appended to the section.txt file:
<!--SECTIONS:{'<section begin=1 />': [(152, 990), (1282, 2406), (4078,
4478)], '<section begin=6 />': [(19, 115)], '<section begin=2
/>': [(2443,
2821), (2859, 3256)], '<section begin=4 />': [(1555, 1901)],
'<section
begin=5 />': [(171, 477)], '<section begin=3 />': [(3704,
4042)]}-->
then I run these lines from python idle:
>> for i in range(1000):
f=open("section.txt").read()
indici=eval(find_stringa(f,"<!--SECTIONS:","-->"))
t=""
for i in indici["<section begin=1 />"]:
t+=f[i[0]:i[1]]
As you see the code, for 1000 times:
opens the file and loads it
selects "data area" (find_stringa is a personal, string seach tool to get
strings), and converts it into a dictionary
retrieves all the text inside multiple sections named "1" (the worst case in
the list: section 1 has three instances: [(152, 990), (1282, 2406), (4078,
4478)]
Time to do 1000 cicles: more or less, 3 seconds on a far from powerful pc.
:-)
Fast, in my opinion!
So, it can be done, and it runs, in an effective way too. Doesn't it?
Alex