Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Very New to Python
#2
To read through the file, use a context manager (with statement) and loop through the file directly:

with log_file as opne('log_test.txt'):
    for line in log_file:
The start method of the string (line will be a string) will allow you to detect the 'edit' and 'next'. I would have a boolean variable and a list of lines to go into the new file. When you hit edit, you switch the boolean to true, after you hit next, switch it to false. If it's true, add the current line to the previous line as one line, when it's false append the new line to the list. Then you can write out the lines to a new file.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Very New to Python - by wfsteadman - Jul-01-2017, 02:11 PM
RE: Very New to Python - by ichabod801 - Jul-01-2017, 04:51 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020