[Tutor] Incrementing a line?

Don Arnold darnold02 at sprynet.com
Tue Dec 9 07:14:32 EST 2003


Untested:

targetLineNum = 0
lineNum = 0

for s in userlog.readlines():
     lineNum++;
     if lineNum == targetLineNum:
         print 'found violation info at line', lineNum
         constraintlog.write(s + '\n')
         targetLineNum = 0
     for word in s.split():
         if word == '19(Constraint':
             targetLineNum = lineNum + 10
             constraintlog.write(s + '\n')

constraintlog.close()

Barring my not actually being awake yet, that might be close.

HTH,
Don

On Dec 9, 2003, at 5:54 AM, Jim Boone wrote:

> Howdy all, i hope this is the right list for my query, pythons a bit 
> new to me, and I'm trying dto something that I can't figure out:
>
> for s in userlog.readlines():
>            for word in s.split():
>                if word == ("19(Constraint"):
>                    constraintlog.write(s + "\n")
>                    print "\n\n*****Constraint Violations 
> exist!!*****\n\n"
>        constraintlog.close()
>
> Is a section of code i have, it reads a log file and cranks out a log 
> file on a certain condition, I can get it to write out the same line 
> which is in the original log file, which is useful, but, what would be 
> much more useful is if i could write out the line thats 10 lines after 
> the "19(Constraint", because it's more pertinent, but of course s+10 
> is stupidly wrong.
>
> Any help appreciated, Thanks!
>
> -- 
> Jim Boone
> --------------------------------------------
> Buckinghamshire Chilterns University College
> R&D Manager - Information and Communication Technologies
> Tel: 01494 522141 ext 3569
>
> The myth that Bill Gates has appeared like a knight in shining armor 
> to lead all customers out of a mire of technological chaos neatly 
> ignores the fact that it was he who, by peddling second-rate 
> technology, led them into it in the first place, and continues to do 
> so today.
>
> ~Douglas Adams~
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>




More information about the Tutor mailing list