"Pete O'Connell" <pedrooconn...@gmail.com> wrote

I am always looking for the line " name Write1" as my starting point. In the first example below, I want to replace the path, which is 2 lines above it.
I have made a basic script to do that and it works fine. The problem I am
having is when the number of lines between " name Write1" and the path above
it is not 1, my script breaks.

Why not turn the algorithm around and look for the pasth line,
then see if a name Write1 line exists in the same block.

for each Write block:
   find path line and store it
   find name Write1
   if exists: update path

That way you have no dependency on the number of lines and the
only tricky bit is if the path comes after the name Write1 line
Or if there is no path line....

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to